看到国外的牛们在使用这个框架,编译使用之。记录一下过程和问题:
源代码:http://www.cs.unc.edu/~walk/software/glvu/
过程和问题:
1.打开VS2008,全部转换至2008工程(初始工程是6.0版本的)
2.替换全部#include <iostream.h>为 #include <iostream>
3.将glut头文件放在#include <stdlib.h>后面,否则报错 err
4.编译成功,但是例子运行提示连接lib 有错。
5.直接改造glut.h ,呵呵,改造后头函数头部如下:
#ifndef __glut_h__
#define __glut_h__
/* Copyright (c) Mark J. Kilgard, 1994, 1995, 1996, 1998. */
/* This program is freely distributable without licensing fees and is
provided without guarantee or warrantee expressed or implied. This
program is -not- in the public domain. */
// 邵延华 添加,防止对glut.lib 的连环依赖,有错
/**//** 定义避免在glut使用atexit*/
#ifndef GLUT_DISABLE_ATEXIT_HACK
#define GLUT_DISABLE_ATEXIT_HACK
#endif
#ifdef WIN32
#include<windows.h>
#endif
#include <stdlib.h>
6.设置编译器可以连接到我们编译产生的lib。
7.编译例子
key code://============================================================================ // example_2window.cpp : most basic multi-window GLVU example //============================================================================ #include <glvu.hpp> //---------------------------------------------------------------------------- // USER-PROVIDED INCLUDES //---------------------------------------------------------------------------- #include <GL/glut.h> //---------------------------------------------------------------------------- // GLOBALS //---------------------------------------------------------------------------- #define NUM_GLVUS 2 GLVU GLVUs[NUM_GLVUS]; //---------------------------------------------------------------------------- // USER-PROVIDED DRAWING ROUTINE //---------------------------------------------------------------------------- void userDisplayFunc0() { GLVUs[0].BeginFrame(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1,0,0); glutSolidTeapot(1); GLVUs[0].EndFrame(); } void userDisplayFunc1() { GLVUs[1].BeginFrame(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0,1,0); glutSolidTeapot(1); //glutSolidTorus(1.0,2.0,10,10); GLVUs[1].EndFrame(); } void InitOpenGL0() { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); } void InitOpenGL1() { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); } //---------------------------------------------------------------------------- // MAIN ROUTINE. INIT USER OBJECTS AND ACTIVATE VIEWER. //---------------------------------------------------------------------------- int main(int argc, char *arv[]) { //-------------------------------------------------------------------------- // TO USE THE VIEWER: // (1) Instantiate some global GLVUs (one for each window). See top of file. //-------------------------------------------------------------------------- //-------------------------------------------------------------------------- // (2) Init each viewer by specifying menu string, visual mode mask, // and starting position and extents of the window. // After Init, perform any OpenGL initializations and // initialize the viewer cameras. //-------------------------------------------------------------------------- Vec3f m,M,Cntr, Eye,LookAtCntr,Up; m.Set(-1,-1,-1); M.Set(1,1,1); Up.Set(0,1,0); float Yfov = 45; float Aspect = 1; // WIDTH OVER HEIGHT float Near = 0.1f; // NEAR PLANE DISTANCE RELATIVE TO MODEL DIAGONAL LENGTH float Far = 10.0f; // FAR PLANE DISTANCE (ALSO RELATIVE) // ---- WINDOW 0 INITIALIZATION ---- GLVUs[0].Init("GLVU 2-Window Example (window 0)", GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA, 50,50,512,512); InitOpenGL0(); glutDisplayFunc(userDisplayFunc0); Eye.Set(0,0,3); LookAtCntr.Set(0,0,0); GLVUs[0].SetAllCams(m,M, Eye,LookAtCntr,Up, Yfov,Aspect, Near,Far); // ---- WINDOW 1 INITIALIZATION ---- GLVUs[1].Init("GLVU 2-Window Example (window 1)", GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA, 600,100,500,400); InitOpenGL1(); glutDisplayFunc(userDisplayFunc1); Eye.Set(2,2,3); LookAtCntr.Set(0,0,0); GLVUs[1].SetAllCams(m,M, Eye,LookAtCntr,Up, Yfov,Aspect, Near,Far); //-------------------------------------------------------------------------- // (3) start the viewer event loop. //-------------------------------------------------------------------------- glutMainLoop(); // Control flow will never reach here return EXIT_SUCCESS; }