关于OpenGL和directx的争论一直没有停息过,我并不想告诉你哪个更好,但是比较公认的是OpenGL对于一个初学者更容易理解。下面主要说一下OpenGL的可配置(当然这很简单,但有时候库配置好了仍然出错,希望我的方法可以帮到大家)
以我的为例C:\program files\Microsoft visual stdio\VC98\include\GL下,一般都会有GL文件夹的,没有的话新建一个就行了。
#include<GL\glut.h>
#include <stdlib.h>
void display()
{
}
void init()
{
}
void myKeyboard(unsigned char key,int x,int y)
{
}
int main(int argc, char** argv)
{
}
看看运行结果:
一般来说这样就行了,但是我看到有很多网友按照上面的设置仍然不能运行出正确的OpenGL程序,出现以下错误:
error LNK2001: unresolved external symbol ___glutInitWithExit@12
到v.obj : error LNK2001: unresolved external symbol ___glutCreateWindowWithExit
Debug/大法官.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错
如果用的是gl.h等头文件也有可能出现以下错误:
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2144: syntax error : missing ';' before type 'void'
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : error C2501: 'WINGDIAPI' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\vc98\include\gl\gl.h(1152) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
如果不是库的问题就应该是路径设置
那么你可以试试以下方法:
如果没有则进行设置,分别输入:set include=C:\Program Files\Microsoft Visual Studio\VC98\Include\GL(点击回车)
接着输入:set lib=C:\Program Files\Microsoft Visual Studio\VC98\Lib(点击回车)
(即:include和Lib文件的路径),这样就应该OK了。
感谢百度网友ponglang,在OpenGL方面对我的帮助很多。