Using GCC (MinGW) to compile OpenGL on Windows
I've searched on google and haven't been able to come up with a solution.
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
Then in my system32 file I have the following .dll
opengl32.dll
glu32.dll
glut32.dll
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;
}
I am using WindowsXP and GCC version 3.4.5. Thank you in advance for the help.
You probably want to run gcc like this:
gcc -g -Wall hello_gl.c -lopengl32 -lglu32 -lfreeglut
Unfortunately GLUT does not come preinstalled on Windows.
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.
The official GLUT port to Win32 is available here but it's a bit dated.
I suggest you use the compatible freeglut library instead. You can use this tutorial for setting up freeglut with Mingw32
精彩评论