设置OpenGL时遇到问题
Having trouble setting up 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
这是否意味着某些内容下载不正确,或者我包含了错误的文件?
首先安装所有必需的库
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>
相关文章:
- 编译包含字符串的代码时遇到问题
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 在 for 循环中查找问题时遇到困难
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- 从其他类访问类时遇到问题
- 打印问题.我在数组中打印值时遇到一些问题
- 使用静态成员声明类时遇到问题
- C++ 填充数组时遇到问题
- 遇到此问题时遇到困难:允许用户输入数组的值并使用 for,而循环也输出输入的最大数字
- 我在使用C++文件时遇到了一些问题
- 在将字符串放入字符串向量时遇到问题?
- 余数除法和不允许除以零 (c++) 时遇到问题
- 我在C++中使用 getline() 函数时遇到问题
- C++线程安全:如果只有一个线程可以写入非原子变量,但多个线程从中读取. 会遇到问题吗?
- 在我的四叉树实现中遇到问题
- 在 c++ 中循环遍历数组时遇到问题
- 我遇到了黑客排名中的问题"TWO STRINGS"的三个测试用例的分段错误。原因是什么?
- 使用 MinGW 在 Windows 上构建 GLEW 时遇到问题
- 编译 Cilk Plus 程序时遇到问题