另一个OpenGL SuperBible第5版设置问题

那么,我刚刚买了这个opengl超级宝典(第五版)。 不幸的是,我偶然发现了如何设置opengl本身的第一章。 这是我做的一步。

(1)首先,我安装了Microsoft Visual Studio 2010 C ++ Express

(2)我下载了需要的库,至于这个我直接从opengl superbible的官方站点下载: http : //www.starstonesoftware.com/files/SB5.zip 。 然后我解压到我的本地文件夹中的文件。

(3)然后我创build新的空项目。
文件 – >新build – >项目 – > Visual C ++安装模板 – >常规 – >空项目

(4)为freeglut和gltools文件头添加额外的include目录path。
项目 – >属性 – >configuration属性 – >(然后我设置configuration=所有configuration) – > C / C ++ – >常规 – >其他包含目录。
这里我添加两个目录:
(a)freeglut:[我的本地path] \ SB5 \ freeglut-2.6.0 \ include
(b)gltools:[我的本地path] \ SB5 \ Src \ GLTools \ include

(5)为freeglut和gltools文件头添加额外的依赖path。
项目 – >属性 – >configuration属性 – >(然后我设置configuration=所有configuration) – >连接器 – >input – >其他依赖项。
(a)中freeglut_static.lib
(b)中GLTools.lib

(6)添加库目录。
项目 – >属性 – >configuration属性 – >(然后我设置configuration=所有configuration) – > VC ++目录 – >库目录。 在这里我设置freeglut_static.lib和GLTools.lib目录的位置
(a)freeglut_static.lib:[我的本地path] \ SB5 \ freeglut-2.6.0 \ VisualStudio2008Static \ Release
(b)GLTools.lib:[我的本地path] \ SB5 \ VisualStudio2008 \ GLTools \ Release

(7)之后,我复制的源代码(Triangle.cpp),但我没有忘记包括windows.h在第一行。

// Triangle.cpp // Our first OpenGL program that will just draw a triangle on the screen. #include <Windows.h> #include <GLTools.h> // OpenGL toolkit #include <GLShaderManager.h> // Shader Manager Class #ifdef __APPLE__ #include <glut/glut.h> // OS X version of GLUT #else #define FREEGLUT_STATIC #include <GL/glut.h> // Windows FreeGlut equivalent #endif GLBatch triangleBatch; GLShaderManager shaderManager; /////////////////////////////////////////////////////////////////////////////// // Window has changed size, or has just been created. In either case, we need // to use the window dimensions to set the viewport and the projection matrix. void ChangeSize(int w, int h) { glViewport(0, 0, w, h); } /////////////////////////////////////////////////////////////////////////////// // This function does any needed initialization on the rendering context. // This is the first opportunity to do any OpenGL related tasks. void SetupRC() { // Blue background glClearColor(0.0f, 0.0f, 1.0f, 1.0f ); shaderManager.InitializeStockShaders(); // Load up a triangle 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(); } /////////////////////////////////////////////////////////////////////////////// // Called to draw scene void RenderScene(void) { // Clear the window with current clearing color 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(); // Perform the buffer swap to display back buffer glutSwapBuffers(); } /////////////////////////////////////////////////////////////////////////////// // Main entry point for GLUT based programs 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; } 

(8)第7步之后,我build立了这个项目,一切都还顺利。 这是build立的结果:

 1>------ Build started: Project: superbible1, Configuration: Debug Win32 ------ 1> main.cpp 1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library 1>GLTools.lib(GLBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info 1>GLTools.lib(glew.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(glew.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info 1>GLTools.lib(GLShaderManager.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLShaderManager.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info 1>GLTools.lib(GLTools.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTools.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info 1>GLTools.lib(GLTriangleBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'GLTools.lib(GLTriangleBatch.obj)' or at 'C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\vc90.pdb'; linking object as if no debug info 1> superbible1.vcxproj -> C:\Documents and Settings\Tony\My Documents\Visual Studio 2010\Projects\superbible1\Debug\superbible1.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== 

(9)我运行程序时出现了问题。 我得到运行时错误。 这个消息有一个警告对话框:

 Unhandled exception at 0x00000000 in superbible1.exe: 0xC0000005: Access violation reading location 0x00000000. 

当我select中断程序时,光标停在了这一行:

  GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f }; 

那么如果我改变这个代码与另一个简单的代码(从opengl红皮书)。 比如像这样:

 #define FREEGLUT_STATIC #include <Windows.h> #include <GL\glut.h> void display(void) { /* clear window */ glClear(GL_COLOR_BUFFER_BIT); /* draw unit square polygon */ glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5); glEnd(); /* flush GL buffers */ glFlush(); } void init() { /* set clear color to black */ /* glClearColor (0.0, 0.0, 0.0, 0.0); */ /* set fill color to white */ /* glColor3f(1.0, 1.0, 1.0); */ /* set up standard orthogonal view with clipping */ /* box as cube of side 2 centered at origin */ /* This is default view and these statement could be removed */ /* glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); */ } int main(int argc, char** argv) { /* Initialize mode and open a window in upper left corner of screen */ /* Window title is name of program (arg[0]) */ /* You must call glutInit before any other OpenGL/GLUT calls */ glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("simple"); glutDisplayFunc(display); init(); glutMainLoop(); } 

应用程序可以运行良好。 所以我想也许有代码有问题或者可能有我想念的东西。 所以任何人都可以帮忙

GLfloat vVerts[] = { -0.5f, 0.0f, 0.0f, ...不能是问题。 但是Visual的绿色调试光标显示将被执行的NEXT行,所以我怀疑它是shaderManager.InitializeStockShaders(); 那崩溃。

我不知道这是什么,但它可能读取文件…确保它找到它们。 尤其是,根据压缩文件的内容,直接从资源管理器中运行.exe。

我也刚刚开始。

如果你打算通过所有的例子,最好将所有的freeglut / GLTools .h.lib文件复制到VC ++ 2010的相关目录中。

你仍然必须在源代码中包含windows.h ,并且还必须具体告诉VC ++ 2010使用GLTools.lib (链接器,输入,附加依赖)。

这显然解释了如何摆脱所有的pdb错误,如果他们打扰你。