Opengl奇书第5版代码问题

| 我已经开始阅读精湛的第5版,而且我陷在第一个程序中。当我使用xp和vs2008时,我已经按照书中提供的所有说明来设置vs2008以运行三角程序,但是在编译过程之后,它显示了一个错误,我不知道为什么会这样发生。该程序如下:
// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.

#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 the 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;
}
错误显示是这个
1>d:\\opengl\\SB5\\freeglut-2.6.0\\VisualStudio2008Static\\Release\\freeglut_static.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x3
1>Build log was saved at \"file://c:\\Documents and Settings\\Administrator\\My Documents\\Visual Studio 2008\\Projects\\dfdf\\Debug\\BuildLog.htm\"
有人可以帮我解决这个问题吗?谢谢。
已邀请:
我认为您的问题不在代码之外。我追溯了什么
#define FREEGLUT_STATIC 
这样做,然后弹出:
#   ifdef FREEGLUT_STATIC

#       define FGAPI
#       define FGAPIENTRY

        /* Link with Win32 static freeglut lib */
#       if FREEGLUT_LIB_PRAGMAS
#           pragma comment (lib, \"freeglut_static.lib\")
#       endif
但是,如果您从freeglut Windows Development Libraries下载了准备好的软件包,则只​​会得到freeglut.lib。因此,要么必须使用freeglut自己构建\“ freeglut_static.lib \”,要么不使用静态宏,就可以了。链接器只是在说它正在经历什么-无法找到您的文件,因此无法读取... 和BTW:这本书的内容是一回事,但也许您跳过了一些内容,或者它们只是未包含其中,但是当您下载干净的freeglut时,VisualStudio2008Static文件夹不包含任何库,而仅包含另一个文件夹和Visual Studio项目。您需要打开该项目,在MSVC(构建->配置管理器)中选择发行版本并构建项目。您可以在release文件夹中获得freeglut_static.lib。
您收到的错误消息表明freeglut_static.lib文件已损坏。您最好重新安装该库以确保文件已正确复制,或者您可以尝试从源代码重建该库。 可能值得尝试从另一个网站获得预构建的版本,也许您可​​以从这里获得的Visual Studio版本获得更多的运气。

要回复问题请先登录注册