1.
首先需在stdafx.h中加入以下头文件
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <gl/glaux.h>
此处切记要加在
// _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
之间,
“Microsoft Visual C++ will insert additional declarations immediately before the previous line”已提示你要这样做了
如果你将Opengl库头文件放在stdafx.h的开始或其他位置
会出现如下连接错误:
c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ';' before type 'void'
c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\program files (x86)\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
一般网上都会教你再加#include <windows.h>
那样的话又会提示“WINDOWS.H already included. ”如此以来便陷入死锁的境地。当然,非MFC的WIN32程序在使用OpenGL时确实应该将#include <windows.h>放在【opengl……】.h之前,这是必须的,但MFC则无须。
关键时opengl配置库文件要放入正确位置。
2:
在C[project]view.h中切记不要随便加入变量,因为MFC中,有好多cpp扩入了C[project]view的头文件,会出现重定义,在配置MFC 中的OpenGL环境是误看了内容,将
HGLRC m_hRC; //Rendering Context
CDC* m_pDC; //Device Context
当做了全局变量放在C[project]view的头文件中,导致Link时出现错误如下:
myOpenGLView.obj : error LNK2005: "struct HGLRC__ * m_hRC" (?m_hRC@@3PAUHGLRC__@@A) already defined in myOpenGL.obj
myOpenGLView.obj : error LNK2005: "class CDC * m_pDC" (?m_pDC@@3PAVCDC@@A) already defined in myOpenGL.obj
Creating browse info file....
找到解决办法对于此类“error LNK2005……already defined”的错误,一般而言是因变量重复定义了且又被几个.c(pp)所包含
参考如:点击打开链接