在Windows上使用GCC(MinGW)编译OpenGL [英] Using GCC (MinGW) to compile OpenGL on Windows
问题描述
我在google上搜索过,还没有找到解决方案.
I've searched on google and haven't been able to come up with a solution.
我想使用GCC编译一些OpenGL编程.在GCC的GL文件夹中,我有以下标题:
I would like to compile some OpenGL programming using GCC. In the GL folder in GCC I have the following headers:
gl.h
glext.h
glu.h
然后在我的system32文件中,我有以下.dll
Then in my system32 file I have the following .dll
opengl32.dll
glu32.dll
glut32.dll
如果我想编写一个简单的OpenGL"Hello World"并与GCC链接并进行编译,正确的过程是什么?
If I wanted to write a simple OpenGL "Hello World" and link and compile with GCC, what is the correct process?
我正在尝试使用以下代码:
I'm attempting to use this code:
#include <GL/gl.h>
#include <GL/glut.h>
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitWindowSize(512,512);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("The glut hello world program");
glutDisplayFunc(display);
glClearColor(0.0, 0.0, 0.0, 1.0);
glutMainLoop(); // Infinite event loop
return 0;
}
我正在使用WindowsXP和GCC版本3.4.5.预先感谢您的帮助.
I am using WindowsXP and GCC version 3.4.5. Thank you in advance for the help.
推荐答案
您可能想像这样运行gcc:
You probably want to run gcc like this:
gcc -g -Wall hello_gl.c -lopengl32 -lglu32 -lfreeglut
不幸的是,GLUT尚未预装在Windows上.
Unfortunately GLUT does not come preinstalled on Windows.
GLUT是一个库,它负责为您创建窗口和图形上下文的(特定于平台)工作.许多OpenGL示例都使用它.
GLUT is a library that takes care of the (platform specific) job of creating a window and graphic context for you. Many OpenGL samples use it.
可以在此处使用到Win32的官方GLUT端口,但这有点陈旧.
The official GLUT port to Win32 is available here but it's a bit dated.
我建议您改用兼容的 freeglut 库.您可以使用本教程通过Mingw32设置freeglut
I suggest you use the compatible freeglut library instead. You can use this tutorial for setting up freeglut with Mingw32
这篇关于在Windows上使用GCC(MinGW)编译OpenGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!