OpenGL:无法使用freeGLUT执行渲染? C ++

时间:2013-02-09 00:34:34

标签: c++ opengl render freeglut

我今天刚开始使用freeGLUT,我已经很好地安装了所有东西。我能够创建一个基本窗口,但每当我调用几乎每个渲染方法时,编译都会失败。我使用以下代码:

#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 `glClear@4'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:31: undefined reference to `glBegin@4'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:32: undefined reference to `glColor3f@12'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:33: undefined reference to `glVertex2f@8'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:34: undefined reference to `glColor3f@12'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:35: undefined reference to `glVertex2f@8'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:36: undefined reference to `glColor3f@12'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:37: undefined reference to `glVertex2f@8'
C:\Users\User\Dropbox\NetBeans Workspace\OpenGL_Testing/main.cpp:38: undefined reference to `glEnd@0'

我做错了什么,还是我错过了一个导入?

1 个答案:

答案 0 :(得分:4)

通过错误消息,它看起来像Windows。您需要链接到opengl32.lib