好的,我在 Windows 7 上设置 Visual studios C++ 10,这样我就可以运行《OpenGL superible 第五版》这本书中的示例程序,但我在使用 GLTools 和 freeglut 时遇到了一些重大问题:
到目前为止,我是这样设置所有内容的............
拳头遵循了我上网的以下步骤:
首先你要下载 glut 或 freeglut,然后解压它。
- 我从 zip 文件中得到这个http://www.starstonesoftware.com/OpenGL/ http://www.starstonesoftware.com/OpenGL/
在freeglut文件夹中应该有一个名为VisualStudio2008的文件夹,进入这个文件夹。
应该有一个名为 freeglut 的 VS 项目文件,运行该文件,如果出现转换窗口,请单击“完成”。然后编译,如果编译完成后提示无法启动,就可以了。
现在在同一个文件夹中应该有一个名为 Debug 的新文件夹,因为您刚刚将 freeglut 编译到了它:)。
在里面你会发现 freeglut.dll。这需要分别进入您的 system32 文件夹或 SysWOW64 文件夹。
除此之外,还有一个名为 freeglut 的文件,其类型为对象文件库。这需要进入 Visual Studio 中的 lib 文件夹。
现在返回主 freeglut 文件夹。应该有一个名为 Include 的文件夹。其中有一个名为 GL 的文件夹和两个文件。这些需要复制到 Visual Studio 中的 Include 文件夹中。
lib 和 Include 文件夹位于 VC 文件夹内,该文件夹位于主 Visual Studio 文件夹中,对我来说是 Microsoft Visual Studio 10.0 。
在那里:)。`
然后我按照以下步骤设置 GLTools 和 freeglut:
这需要计算机的管理员权限。
我。将所有 freeglut 头文件(以 .h 结尾)复制到该文件夹:
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\GL\
二.将所有 GLTools 头文件(以 .h 结尾)复制到
C:\Program Files\Microsoft Visual Studio 10.0\VC\include\
三.将所有 freeglut 和 GLTools 库文件(以 .lib 结尾)文件复制到
C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\
四.即使您已经复制了 GLTools.lib
进入 lib 文件夹,您可能仍然需要
告诉VS2010使用GLTools.lib文件
编译项目时。打开
物业经理(您需要一个开放的
项目来做到这一点),从菜单选项
查看 → 物业经理。左边
VS IDE 的手窗格将更改为
给物业经理看。你可以
调整其大小以使其更具可读性。
如果完整列表是,则展开项目
未显示,然后双击其中之一
Microsoft.Cpp.Win32.user 链接到
打开用户属性对话框。
在属性管理器中,选择链接器→输入,然后单击附加
依赖关系(见下文)。在弹出的对话框中添加“GLTools.lib”,
我还添加了 Feeglut_static.lib !
好吧,最后这是我要运行的代码:
#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;
}
最后,这是接收错误:
1>------ Build started: Project: Triangle, Configuration: Debug Win32 ------
1> Triangle.cpp
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(225): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(225): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(226): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(226): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(226): error C2086: 'int GLAPI' : redefinition
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(225) : see declaration of 'GLAPI'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(227): error C2144: syntax error : 'void' should be preceded by ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(227): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(227): error C2086: 'int GLAPI' : redefinition
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\gl\glu.h(225) : see declaration of 'GLAPI'
错误 C1003:错误计数超过 100;停止编译
这种情况永远持续下去,我不知道怎么会出现这样的问题,也不知道为什么它会发生在 GLU.h 中!我真的不知道出了什么问题,我已经遇到这个问题一周了......
请帮忙=)
谢谢,如有任何问题,请随时提出!