#include "glut.h"的作用
时间: 2023-09-25 07:09:52 浏览: 46
`#include "glut.h"` 是在 C++ 程序中包含 GLUT(OpenGL Utility Toolkit)库的头文件,使得程序可以使用 GLUT 库提供的函数和数据类型。
GLUT 是一个开源的跨平台工具包,可以用于创建基于 OpenGL 的交互式计算机图形应用程序。它提供了一些常用的功能,如窗口管理、事件处理、用户输入、计时器、定时器等,简化了 OpenGL 编程的流程,让开发者更专注于图形算法和交互设计。
通过包含 `glut.h` 头文件,程序可以使用 GLUT 提供的函数和数据类型,比如创建窗口、注册回调函数、处理输入事件、绘制图形等。例如,`glutCreateWindow()` 可以创建一个窗口,`glutDisplayFunc()` 可以注册一个回调函数来绘制图形,`glutMainLoop()` 可以启动事件循环,等待用户输入并处理事件。
相关问题
我的头文件是这样写的#include <stdio.h> #include <math.h> #include <fstream> #include <iostream> #include <string>//getline #include <sstream> #include "stb_image.h" #pragma comment(lib, "openGL32.lib") #pragma comment(lib, "glu32.lib") #pragma comment(lib, "glaux.lib") #include <gl/glaux.h> #include "glew.h" #include "glut.h" #include <vector>,请问如何避免报错gl.h included before glew.h呢
在你的头文件中,应该将 `glew.h` 的引入放在 `gl.h` 的引入之前。因此,你应该将 `glew.h` 的引入语句移到 `gl.h` 的引入语句之前,就像这样:
```
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include <string>//getline
#include <sstream>
#include "stb_image.h"
#include <gl/glaux.h>
#include <vector>
#include "glew.h"
#include <gl/glut.h>
#pragma comment(lib, "openGL32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")
```
这样就能够避免 `gl.h included before glew.h` 的错误了。
#include <GL/glut.h
将glut.h文件复制到Microsoft Visual Studio的include文件夹中的GL文件夹里。您可以在路径D:\VC\Tools\MSVC\14.33.31629\include\GL找到它。然后,将测试程序复制到您的项目中,包括#include <GL/glut.h>和其他OpenGL函数和窗口创建代码。您可以使用以下代码作为示例:
#include <GL/glut.h>
void myDisplay() {
glClear(GL_COLOR_BUFFER_BIT);
glRectf(-0.5f, -0.5f, 0.5f, 0.5f);
glFlush();
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(400, 400);
glutCreateWindow("第一个OpenGl程序");
glutDisplayFunc(&myDisplay);
glutMainLoop();
return 0;
}
参考链接:OpenGL学习(一)freeglut / GLEW环境搭建与窗口创建_AKGWSB's blog-CSDN博客