2013-02-09 60 views
0

我剛開始使用freeGLUT,並且已經很好地安裝了所有東西。我可以創建一個基本的窗口,但每當我調用幾乎每種渲染方法時,編譯都會失敗。我使用下面的代碼:OpenGL:無法使用freeGLUT執行渲染? C++

#include "math_lib.h" 
#include <stdlib.h> 
#include <GL/freeglut.h> 

void render(void); 

int main(int argc, char** argv) { 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); 
    glutInitWindowPosition(100, 100); 
    glutInitWindowSize(640, 480); 
    glutCreateWindow("Simple GLUT Application"); 

    glutDisplayFunc(render);  

    glutMainLoop(); 
} 

void render(void) { 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

    glBegin(GL_TRIANGLES); 
     glColor3f(1, 0, 0); 
     glVertex2f(-0.5, -0.5); 
     glColor3f(0, 1, 0); 
     glVertex2f(0.5, -0.5); 
     glColor3f(0, 0, 1); 
     glVertex2f(0.0, 0.5); 
    glEnd(); 

    glutSwapBuffers(); 
} 

而我得到的錯誤是:

C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:29: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:31: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:32: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:33: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:34: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:35: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:36: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:37: undefined reference to `[email protected]' 
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:38: undefined reference to `[email protected]' 

所以我做錯了什麼,或我只是缺少一個導入?

回答

4

由錯誤消息它看起來像Windows。您需要鏈接到opengl32.lib

+0

我沒有那個文件在我的電腦上的任何地方?它是否帶有freeglut zip文件? – CoderTheTyler 2013-02-09 00:39:27

+0

等不了了之......我找到了!只是我再次愚蠢..雖然謝謝!我會盡力鼓勵 – CoderTheTyler 2013-02-09 00:43:23