gpt4 book ai didi

c++ - Opengl superbible example compliation errors 源代码 : drawing a triangle

转载 作者:行者123 更新时间:2023-11-30 02:37:46 25 4
gpt4 key购买 nike

我是 OpenGL 的新手,我现在正在尝试书中的例子,我已经正确地包含了所有的库和头文件,但似乎还有一些不对劲。

这些是我包含的 header :

enter image description here enter image description here enter image description here

这是代码:

// 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>------ Build started: Project: openglproj, Configuration: Debug Win32 ------
1>Compiling...
1>Triangle.cpp
1>d:\xing bizhou\project\openglproj\triangle.cpp(57) : error C2065: '“Triangle”' : undeclared identifier
1>d:\xing bizhou\project\openglproj\triangle.cpp(62) : error C2065: '“GLEW' : undeclared identifier
1>d:\xing bizhou\project\openglproj\triangle.cpp(62) : error C2146: syntax error : missing ')' before identifier 'Error'
1>d:\xing bizhou\project\openglproj\triangle.cpp(62) : error C2017: illegal escape sequence
1>d:\xing bizhou\project\openglproj\triangle.cpp(62) : error C2059: syntax error : ')'
1>Build log was saved at "file://d:\XING BIZHOU\project\openglproj\openglproj\Debug\BuildLog.htm"
1>openglproj - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

最佳答案

您在代码中使用了“漂亮的引号”。

C++ 需要一个特定字符 " 用作双引号。它可能不会被类似的字符替换。

改变:

“三角形”“GLEW 错误:%s\n”

收件人:

“三角形”“GLEW 错误:%s\n”

关于c++ - Opengl superbible example compliation errors 源代码 : drawing a triangle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com