Wednesday, April 14, 2010

How to use “FreeGLUT” on windows with MinGW and Qt Creator


GLUT has been a very popular light weight library for student and enter-level researchers for years, as its clear structure, not excluded I mean, small size and perfect connectivity with OpenGL. However, GLUT is not a free software and has not been maintained for a while, although I am not sure about the maintainability of GLUT, it has been same since I was an undergraduate and learn OpenGL first time. So FreeGLUT is another recommended option for GLUT people.
In recent days, I am trying to compile and program some code on Window with GCC/G++. My first idea is Cygwin, which is an total solution for GNU stuff on Windows. However, the problem is that Cygwin does not have a IDE for Qt development and you have to take care all of the make file and dependence. Instead, I think MinGW is an executable substitution. Qt Creator is based on MinGW and Qt library has been deployed on MinGW. So, comparing the problem caused by Qt on Cygwin and make file, I prefer to transplant FreeGLUT to MinGW!
Ok, let us begin the instruction! The installation of FreeGLUT is simple! As I mentioned, FreeGLUT is a light weighted, the package is small. Some kind hearted people has been compiled the source code and publish it on the web. Thanks for that! You may download a package called “freeglut-MinGW-2.6.0-3.mp.zip” and unzip it. You gonna get two folders and a DLL( if you do not know what is DLL, forget about it)! Please copy the header files in “include/GL” to “include/GL”, which may under “C:\Qt\2010.02.1\mingw\”, and copy the lib files in “lib” to “C:\Qt\2010.02.1\mingw\lib”. Then you need to copy the “freeglut.dll” to system32, or sysWOW64, if you are using a 64 bit computer. The next step is configure Qt creator. Make sure that your PRO file has “QT += opengl” and “LIBS += libfreeglut”! That is all, enjoy the “Hello world” below!

If you want to know something about static linking or beyond, please chech this blog:
http://www.transmissionzero.co.uk/computing/using-glut-with-mingw/

#include
#include

void keyboard(unsigned char key, int x, int y);
void display(void);

int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutCreateWindow("GLUT Test");
glutKeyboardFunc(&keyboard);
glutDisplayFunc(&display);
glutMainLoop();

return EXIT_SUCCESS;
}


void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case '\x1B':
exit(EXIT_SUCCESS);
break;
}
}


void display()
{
glClear(GL_COLOR_BUFFER_BIT);

glColor3f(1.0f, 0.0f, 0.0f);

glBegin(GL_POLYGON);
glVertex2f(-0.5f, -0.5f);
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();

glFlush();
}

3 comments: