设置OpenGL时遇到问题

Having trouble setting up OpenGL

本文关键字:问题 遇到 OpenGL 设置      更新时间:2023-10-16

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

#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

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

首先安装所有必需的库

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

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

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

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

#include <GL/glut.h>

不要包括所有这些文件,而是尝试只包括:

#include <GL/glut.h>