无法设置OpenGL

时间:2016-07-28 16:43:47

标签: c++ opengl

以下是我从教程中获得的代码:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glcorearb.h>
#include <GL/glext.h>
#include <GL/gl_mangle.h>
#include <GL/glu_mangle.h>
#include <GL/GLwDrawA.h>
#include <GL/GLwDrawAP.h>
#include <GL/glxext.h>
#include <GL/glx.h>


void display() {

    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glColor3f(1, 0, 0); glVertex3f(-0.6, -0.75, 0.5);
    glColor3f(0, 1, 0); glVertex3f(0.6, -0.75, 0);
    glColor3f(0, 0, 1); glVertex3f(0, 0.75, 0);
    glEnd();
    glFlush();
}

int main(int argc, char** argv) {

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

  glutInitWindowPosition(80, 80);
  glutInitWindowSize(400, 300);
  glutCreateWindow("A Simple Triangle");

  glutDisplayFunc(display);

  glutMainLoop();
}

我包含了/ usr / include / GL中的所有内容。我使用RHEL 6。

我收到以下错误:

In function ‘void display()’:
‘mglClear’ was not declared in this scope
‘mglBegin’ was not declared in this scope
‘mglColor3f’ was not declared in this scope
‘mglVertex3f’ was not declared in this scope
‘mglEnd’ was not declared in this scope
‘mglFlush’ was not declared in this scope
‘int main(int, char**)’:
test.cpp:25: error: ‘glutInit’ was not declared in this scope
test.cpp:26: error: ‘GLUT_SINGLE’ was not declared in this scope
test.cpp:26: error: ‘GLUT_RGB’ was not declared in this scope
test.cpp:26: error: ‘glutInitDisplayMode’ was not declared in this scope
test.cpp:28: error: ‘glutInitWindowPosition’ was not declared in this scope
test.cpp:29: error: ‘glutInitWindowSize’ was not declared in this scope
test.cpp:30: error: ‘glutCreateWindow’ was not declared in this scope
test.cpp:32: error: ‘glutDisplayFunc’ was not declared in this scope
test.cpp:34: error: ‘glutMainLoop’ was not declared in this scope

这是否意味着某些内容未正确下载或我包含错误的文件?

2 个答案:

答案 0 :(得分:1)

首先安装所有必需的库

 yum install mesa-libGL
 yum install mesa-libGL-devel
 yum install freeglut-devel

接下来,您需要实际正确编译所有内容:

g++ *.cpp -lGL -lGLU -lglut

并尝试删除所有这些标头并将其替换为

#include <GL/glut.h>

答案 1 :(得分:0)

不要包含所有这些文件,请尝试仅包括:

#include <GL/glut.h>