繁体   English   中英

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

[英]OpenGL: Cannot perform rendering with freeGLUT? C++

我今天刚开始使用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'

那么我是在做错什么还是我只是缺少导入?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM