我最近开始通过SB第五版学习OpenGl,不幸的是他们在第一个例子中被卡住了。OpenGL superbible第5版。 Triangle.cpp
下面的代码:
#include <GLTools.h>
#include <GLShaderManager.h>
#include <GL/glew.h>
#include <GL/glut.h>
GLShaderManager shaderManager;
GLBatch triangleBatch;
void ChangeSize(GLsizei w, GLsizei h);
void ChangeSize(int w, int h){
glViewport(0,0,w,h);
}
void SetupRC(){
//background
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
shaderManager.InitializeStockShaders();
GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f,
0.5f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f};
triangleBatch.Begin(GL_TRIANGLES, 3);
triangleBatch.CopyVertexData3f(vVerts);
triangleBatch.End();
}
void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
GLfloat vRed[] = {1.0f, 0.0f, 0.0f, 1.0f};
shaderManager.UseStockShader(GLT_SHADER_IDENTITY, vRed);
triangleBatch.Draw();
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
//gltSetWorkingDirectory(argv[0]);
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
glutInitWindowSize(800,600);
glutCreateWindow("Triangle");
glutReshapeFunc(ChangeSize);
//
glutDisplayFunc(RenderScene);
GLenum err=glewInit();
if(GLEW_OK != err) {
fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
虽然,我不认为问题出在代码,因为我已经简单地复制从书粘贴它。我已经添加了本书内容中的库,并且还安装了freeglut。所以,现在他找到了我需要的所有标题,但是当我尝试构建时,存在与triangle.cpp本身无关的大量问题列表。这里有一些:
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(183): warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(183): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2146: syntax error : missing ')' before identifier 'width'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2182: 'gltGenerateOrtho2DMat' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(184): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(234): error C2378: 'GLuint' : redefinition; symbol cannot be overloaded with a typedef
1> c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(177) : see declaration of 'GLuint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(235): error C2378: 'GLint' : redefinition; symbol cannot be overloaded with a typedef
1>c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(162) : see declaration of 'GLint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(238): error C2378: 'GLbyte' : redefinition; symbol cannot be overloaded with a typedef
1> c:\users\whatever\desktop\sb5\src\gltools\include\gltools.h(153) : see declaration of 'GLbyte'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(804): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(804): error C2143: syntax error : missing ',' before '*'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2146: syntax error : missing ')' before identifier 'i'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2182: 'glArrayElement' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2491: 'glArrayElement' : definition of dllimport data not allowed
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(805): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(807): error C2061: syntax error : identifier 'GLuint'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2146: syntax error : missing ')' before identifier 'list'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2182: 'glCallList' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2491: 'glCallList' : definition of dllimport data not allowed
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(810): error C2059: syntax error : ')'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2146: syntax error : missing ')' before identifier 's'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): warning C4229: anachronism used : modifiers on data are ignored
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2182: 'glClearStencil' : illegal use of type 'void'
1>c:\users\whatever\desktop\sb5\src\gltools\include\gl\glew.h(817): error C2491: 'glClearStencil' : definition of dllimport data not allowed
我真的不能做任何事情。它看起来好像错误是在头部本身。就像这些,还有其他几百个头文件。我希望对于我想要揭露的问题,我有足够的了解。如果有什么不清楚的地方,请随时询问。我会尽量少模糊
另外,我使用Microsoft Visual C++ 2010
您是否试过[下载源代码](http://code.google.com/p/oglsuperbible5/)并直接编译它,而不是复制到自己的项目中? – 2012-02-19 16:17:58
我有。奇怪的(或不是),即使在那个特定的文件中,我也遇到了同样的问题,其他项目的构建和运行都很好。 – 2012-02-19 17:34:49