2

我在 Windows 7 64 位笔记本电脑(HP Pavilion g6)上运行 Visual Studio 2010 Professional

非官方 OpenGL SDK: http: //glsdk.sourceforge.net/docs/html/index.html

非官方的 OpenGL SDK、GLew 和 GLee 都是最新的,在适当的地方有匹配的驱动程序、库和头文件

设置:

Preprocessor either over the entire project OR over the main.c file: GLEW_STATIC

Additional Include Directories:
C:/glsdk_0.4.2/glload/include;C:/glsdk_0.4.2/glimg/include;C:/glsdk_0.4.2/glutil/include;C:/glsdk_0.4.2/glmesh/include;C:/glsdk_0.4.2/glm;C:/glsdk_0.4.2/glfw/include;C:/glsdk_0.4.2/freeglut/include;

Additional Library Directories:
C:/glsdk_0.4.2/glload/lib;C:/glsdk_0.4.2/glimg/lib;C:/glsdk_0.4.2/glutil/lib;C:/glsdk_0.4.2/glmesh/lib;C:/glsdk_0.4.2/glfw/library;C:/glsdk_0.4.2/freeglut/lib;

Also tried adding C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib/glew32s.lib (or glew32, glew32mx & glew32mxs);C:/Program Files (x86)/Microsoft SDKs/Windows/v7.0A/Lib/OpenGL32.lib; in Linker -> Input -> Additional Dependancies

Path Inputs (Changed through Environment Variables. Excluding irrelevant entries):
C:\glsdk_0.4.2\glutil\lib;C:\glsdk_0.4.2\freeglut\lib;C:\glsdk_0.4.2\glfw\library;C:\glsdk_0.4.2\glload\lib;C:\glsdk_0.4.2\glimg\lib;

GLew & GLee lib files are located in:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib
Also tried with them located at:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib

GLew & GLee header files are located in:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL
Also tried with them located at:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\GL

从“OpenGL Distilled”复制的代码(标题除外),ISBN10 - 0-321-33679-8:

    #include <stdio.h>
    #include <math.h>

    // Uncomment for GLee ( Also comment out glutInit(&argc, argv); )
    //#include <GL\GLee.h>

    // Uncomment for GLew
    /*#include <GL\glew.h>
    #include <GL\wglew.h>
    #include <GL\glut.h>
    #include <GL\glext.h> */

    // Uncomment for all headers in the "Unofficial OpenGL SDK"
    /*#include <glload\gl_all.h>
    #include <GL\glut.h>
    #include <glload\gll.h>
    #include <glimg\glimg.h>
    #include <glutil\glutil.h>
    #include <glmesh\glmesh.h>
    #include <GL\glfw.h>
    #define FREEGLUT_STATIC
    #define _LIB
    #define FREEGLUT_LIB_PRAGMAS 0
    #include <GL\freeglut.h> */


    int main(int argc, char* argv[])
    {
        glutInit(&argc, argv);

        // Obtain a buffer identifier from OpenGL
        GLuint bufferID = 0;
        glGenBuffers( 1, &bufferID );

        // Bind the buffer object, OpenGL initially creates it empty.
        glBindBuffer( GL_ARRAY_BUFFER, bufferID );

        // Define three vertices to draw a right angle triangle.
        const GLfloat vertices[] = [
            0.f, 0.f, 0.f,
            1.f, 0.f, 0.f,
            0.f, 1.f, 0.f };

        // Tell OpenGL to copy data from the 'vertices' pointer into
        // the buffer object
        glBufferData(GL_ARRAY_BUFFER, 3*3*sizeof(GLfloat), vertices, GL_STATIC_DRAW );
        return 0;
    }

错误:

With GLee:
1>gl_crap3.obj : error LNK2001: unresolved external symbol _GLeeFuncPtr_glBufferData
1>gl_crap3.obj : error LNK2001: unresolved external symbol _GLeeFuncPtr_glBindBuffer
1>gl_crap3.obj : error LNK2001: unresolved external symbol _GLeeFuncPtr_glGenBuffers

With the Unofficial OpenGL SDK:
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___gleBufferData
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___gleBindBuffer
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___gleGenBuffers

With GLew:
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___glewBufferData
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___glewBindBuffer
1>gl_crap3.obj : error LNK2001: unresolved external symbol ___glewGenBuffers
4

2 回答 2

2

对于 SDK,您的 Visual Studio 项目应具有以下设置(sdkbase您解压缩和编译 SDK 的目录的路径在哪里)。

C/C++->General->Additional Include Directories

sdkbase\glload\include;sdkbase\glimg\include;sdkbase\glutil\include;sdkbase\glmesh\include;sdkbase\glm;sdkbase\freeglut\include;sdkbase\glfw\include

Linker->General->Additional Library Directories

sdkbase\glload\lib;sdkbase\glimg\lib;sdkbase\glutil\lib;sdkbase\glmesh\lib;sdkbase\freeglut\lib;sdkbase\glfw\library

Linker->Input/Additional Dependencies, 对于调试版本:

glloadD.lib glimgD.lib glutilD.lib glmeshD.lib freeglutD.lib glfwD.lib glu32.lib opengl32.lib gdi32.lib winmm.lib user32.lib

对于发布版本:

glload.lib glimg.lib glutil.lib glmesh.lib freeglut.lib glfw.lib glu32.lib opengl32.lib gdi32.lib winmm.lib user32.lib
于 2012-08-02T15:39:51.657 回答
0

对于不使用非官方 OpenGL SDK 的人,我刚刚遇到了这个问题,感谢 Nicol Bolas 的回答,我意识到我需要 GLEW 的调试库。

对于 Visual Studio,我通过将glew32.lib项目的调试配置 - at linker->input/Additional Dependencies- 替换为glew32s.lib(注意s末尾的)来解决此问题。

在我这样做之后,一切正常。


笔记

虽然您可以在没有此修复的情况下初始化 GLEW 并使用GLEW 特定功能,但一旦您开始调用 OpenGL,您可能会在使用调试符号构建时遇到错误。

于 2012-10-09T04:07:07.917 回答