Dr.Wing

心翼的技术笔记本

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
新建一个Win32 Console Application程序(注意VS2010中新建.CPP的特殊之处) 
1
//Simple.cpp - First OpenGL Program
2 #include <windows.h> //Required for every Windows Program
3 #define GLUT_DISABLE_ATEXIT_HACK
4 #include <gl\glut.h> //Required for using the GLUT library
5 //Perform OpenGL Initialization here
6 void SetupRC()
7 {
8 //Set the background clearing color to blue
9 glClearColor(0.0f,0.0f,1.0f,1.0f);//设置背景色为蓝色
10 }
11 //The drawing callback function
12 void RenderScene()
13 {
14 //Clear the color buffer
15 glClear(GL_COLOR_BUFFER_BIT);
16 //Flush the rendering pipeline
17 glFlush();
18 }
19 void main()
20 {
21 //Choose the display mode settings
22 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//初始化显示模式(单缓冲,RGB)
23 //Create the Window
24 glutCreateWindow("MYOPENGLONE");//创建窗口
25 //Set the RenderScsne function as the display callback
26 glutDisplayFunc(RenderScene);//绘制回调函数,当窗口需要绘制时,GLUT会调用此函数
27 //Initialize OpenGL
28 SetupRC();//初始化OpenGL
29 //Start the GLUT framework
30 glutMainLoop();//开始消息循环
31 }

在VS2010编辑中要注意的一个很严重的问题就是,如下:

unresolved external symbol __imp____glutInitWithExit@12

unresolved external symbol __imp____glutCreateWindowWithExit@8

 

1.将开发库中的.h文件拷贝到Visual C++ 6.0的\Include\GL目录中
2.将.lib文件拷贝到Visual C++ 6.0的\lib目录中
3.将.dll文件拷贝到操作系统的system32目录中

 

我将Visual Studio 2010开发环境都按上面的配置好了,并且程序也是按照书上的那么编写的,可是仍然报错,无法编译通过:

1>error LNK2001: 无法解析的外部符号__imp____glutCreateWindowWithExit@8

2>fatal error LNK1120: 1个无法解析的外部命令



解决方法:
Try define the following line right before including the header, glut.h:

#define GLUT_DISABLE_ATEXIT_HACK

注:一定要恰好在#include glut.h之前加入以上代码。

如:

正确用法

#include "stdafx.h"

#include "windows.h"

#define GLUT_DISABLE_ATEXIT_HACK

#include "gl\glut.h"

但是,如果更改顺序如下就仍然会报相同的错误:

错误用法

#define GLUT_DISABLE_ATEXIT_HACK

#include "stdafx.h"

#include "windows.h"

#include "gl\glut.h"


posted on 2011-07-19 15:31  心翼  阅读(2713)  评论(0编辑  收藏  举报