我是OpenGL的新手,我現在正在嘗試示例,我已經正確地包含了所有的庫,但似乎還有些東西不正確。Opengl superbible示例compliation錯誤源代碼:繪製三角形庫
兩個庫:freeglut_static.lib gltools.lib包含在項目中。
這是代碼:
// 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>Linking...
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Triangle.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main
1>Triangle.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main
1>D:\XING BIZHOU\project\openglproj\Debug\openglproj.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://d:\XING BIZHOU\project\openglproj\openglproj\Debug\BuildLog.htm"
1>openglproj - 3 error(s), 2 warning(s)
'_glewGetErrorString' - 你需要[添加'glew32.lib'](http://stackoverflow.com/q/17370/1888983)。 [google]上的一些好結果(https://www.google.com.au/search?q=error+LNK2019%3A+unresolved+external+symbol+_glewGetErrorString%404+referenced+in+function&oq=error+LNK2019 %3A +懸而未決+外部+符號+ _glewGetErrorString%404 + +引用在+功能&AQS = chrome..69i57.287j0j7&的SourceID =鉻&es_sm = 93&即= UTF-8)。 – jozxyqk
我在項目中添加了glew32.lib,但仍然出現同樣的錯誤? –
我明白爲什麼,因爲我沒有使用圖書館推薦的圖書館,所以這是版本問題,謝謝大家 –