Opengl超级圣经第5版代码问题
Opengl superbible 5th edition code problem
我已经开始读《超级圣经》第五版了,但是我在第一个程序上卡住了。我用的是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: %sn", glewGetErrorString(err));
return 1;
}
SetupRC();
glutMainLoop();
return 0;
}
错误显示如下
1>d:openglSB5freeglut-2.6.0VisualStudio2008StaticReleasefreeglut_static.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x3
1>Build log was saved at "file://c:Documents and SettingsAdministratorMy DocumentsVisual Studio 2008ProjectsdfdfDebugBuildLog.htm"
有人能帮我解决这个问题吗?谢谢你。 我认为你的问题不在代码上。我已经找到了
是什么#define FREEGLUT_STATIC
where and this弹出:
# 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开发库下载准备好的包,你只得到freeglut.lib。所以要么你必须构建"freeglut_static"。或者不使用静态宏,你应该没问题。链接器只是在说它正在经历什么-找不到你的文件,所以无法读取…
和BTW:什么书指示是一回事,但可能你跳过了一些东西,或者他们只是没有包括它,但当你下载干净的freeglut, VisualStudio2008Static文件夹不包含任何库,只是另一个文件夹和visual studio项目。您需要打开该项目,在MSVC(构建->配置管理器)中选择发布版本并构建项目。你会得到freeglut_static。
您得到的错误消息表明freeglut_static。库文件损坏。您最好重新安装库以确保文件被正确复制,或者您可以尝试从源代码重新构建库。
这可能值得尝试从其他网站预构建的版本,也许你会有更多的运气与Visual Studio版本在这里。
相关文章:
- 代码精简版页面变为空白
- 为什么“从'x*'到'y'失去精度”是一个硬错误,什么是适合旧版代码的解决方案
- 试用版代码在 Windows 上的 32 位运行速度比在 Linux 上的 64 位快 2 倍
- C++初级读本第五版字符串练习,要求两段不同的代码提供相同的输出
- 旧版 MFC 代码 (2005) 无法在 VC 2010 上编译
- 使用生成器和发行版扩展c++11随机的教程或示例代码
- GNU GCC:尝试编译发行版时对"WinMain@16"的未定义引用(代码::Blocks)
- 2010 版 MFC 代码在 2013 上不再有效,有什么建议吗?
- 代码精简版调试器错误:无法找到 gdb!在'/usr/bin/gdb'
- 强制转换 const 指针以使用旧版 C 代码
- MS Visual C++2010学习版继续运行旧代码
- BFS的伪代码(来自算法设计,第二版)混淆
- 'Programming: Principles and Practice Using C++'(第2版),作者:Bjarne stroustrup,第3.3章:代码不起作用
- 在代码(.c文件)我如何找到linux发行版名称版本
- 无法使用Microsoft visual studio c++ 2008 express版编译c代码
- 有人能帮助将此asm代码转换为x64版的c++吗
- 代码精简版生成错误'No such file or directory'
- OpenGL圣经第5版代码问题
- Opengl超级圣经第5版代码问题
- 旧版 C/C++ 项目中的死代码检测