|
最近开始研究Opengl,在自己电脑上安装了VS2008(VC++),按照网上的配置方式配置折腾了许久才成功,整理在此,希望能够给其他人带来方便。
===== 下载OPENGL库 ======
可以到OpenGL官网下载。GLUT并不是OpenGL所必须的,但会给我们的学习带来一定的方便,推荐安装。 http://www.opengl.org/resources/libraries/glut/
然后将以下文件分别放到对应目录(可能没有GL文件夹,可以自己创建一个)。
glut.h
glu.h
gl.h
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\GL
glut.32.lib
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\lib
glut32.dll
glu32.gll
C:\WINDOWS\system32
===== 样例测试 =====
以上设置完毕后,可以使用如下样例测试:hello.c(以下样例来自《OPENGL编制指南》,俗称红宝书,opengl开发必看书籍)
1 /*
2 * hello.c
3 * This is a simple, introductory OpenGL program.
4 */
5 #include
6 #include
7
8 void display(void)
9 {
10 /* clear all pixels */
11 glClear (GL_COLOR_BUFFER_BIT);
12
13 /* draw white polygon (rectangle) with corners at
14 * (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
15 */
16 glColor3f (1.0, 1.0, 1.0);
17 glBegin(GL_POLYGON);
18 glVertex3f (0.25, 0.25, 0.0);
19 glVertex3f (0.75, 0.25, 0.0);
20 glVertex3f (0.75, 0.75, 0.0);
21 glVertex3f (0.25, 0.75, 0.0);
22 glEnd();
23
24 /* don't wait!
25 * start processing buffered OpenGL routines
26 */
27 glFlush ();
28 }
29
30 void init (void)
31 {
32 /* select clearing color */
33 glClearColor (0.0, 0.0, 0.0, 0.0);
34
35 /* initialize viewing values */
36 glMatrixMode(GL_PROJECTION);
37 glLoadIdentity();
38 glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
39 }
40
41 /*
42 * Declare initial window size, position, and display mode
43 * (single buffer and RGBA). Open window with "hello"
44 * in its title bar. Call initialization routines.
45 * Register callback function to display graphics.
46 * Enter main loop and process events.
47 */
48 int main(int argc, char** argv)
49 {
50 glutInit(&argc, argv);
51 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
52 glutInitWindowSize (250, 250);
53 glutInitWindowPosition (100, 100);
54 glutCreateWindow ("hello");
55 init ();
56 glutDisplayFunc(display);
57 glutMainLoop();
58 return 0; /* ANSI C requires main to return int. */
59 }
60
===== 建工程 =====
1. 文件->新建->项目->Visual C++->win32控制台应用程序。
2. 输入项目名称:比如demo,其他默认。
3. VS启动项目向导,选择下一步,选择空项目,其他默认,点击完成。
4. 在解决方案资源管理器中,右键源文件,添加现有项,导入刚写好的hello.c文件。
5. 按F7生成解决方案,按F5启动调试。
===== 可能遇到的问题 =====
编译期间可能会出现如下错误:
error LNK2019: 无法解析的外部符号 __imp____glutCreateWindowWithExit@8,该符号在函数 _glutCreateWindow_ATEXIT_HACK@4 中被引用
解决办法:在glut.h文件中添加如下定义:
#define GLUT_DISABLE_ATEXIT_HACK
OK,Enjoy!
OPENGL官方网站:http://www.opengl.org/ |
|
|