I mainly follow the Red Book 7th edition to learn OpenGL which is based on glut. Other references such as the blue OpenGL bible and online tutorials are based on glut as well. And they all need to put codes in a main function. I wonder how to use OpenGL in a project that has no main function, such as a MFC or Qt project, without using glut?
Asked
Active
Viewed 188 times
-1
-
I had two questions when I posted this question. The first is how to use OpenGL in a project which has no main function, such as in a MFC or Qt project. The other is how to used OpenGL without using GLUT. The question was edited. The first question was not obvious because most tutorials were based on a main function. – Aaron Aug 20 '14 at 12:18
1 Answers
0
The basic answer is that GLUT makes life much easier for you than rolling your own games loop that looks after updates and monitors event listeners. I wrote a game some years ago using OpenGL that avoided GLUT - see here.
It put me through a lot of headache having to employ DirectInput for instance to handle keyboard events for instance, but I did have a lot more control over everything.
As a last note, GLUT is very old and lacks some very important functionality that allows you to exit the game loop cleanly. FreeGLUT is about as good as it gets if you really want to focus on learning OpenGL without all the other worrisome stuff I just described.
Regarding Qt specifics, that might help you out.

ButchDean
- 70
- 6
-
Thanks ButchDean. I now only understand how to use OpenGL in a main function using glut/freeglut (as the Red book shows). I am working on a MFC project which is prepared by someone else and now I need to add some animation to the project. The problem is the project didn't use glut and the OpenGL part of the project is encapsulated. I now can define display functions but I have no idea how they are called. That's why I need to look into those two questions posted above. – Aaron Aug 20 '14 at 12:30
-
If I were you, given that you are new to the OpenGL thing, I would take the time to understand the code by maybe rewriting it from the ground up to see what is going on and take it from there. You will be surprised how enlightening that can be! – ButchDean Aug 20 '14 at 13:26
-
I tried to look into the source code of glutDisplayFunc() to see what exactly it does but I couldn't find the code. Simply put, I now define a display() function. If I use glut I can simply use "glutDisplayFunc(display) in the main() function to display the content. What shall I do if I do not use the glutDisplayFunc()? – Aaron Aug 22 '14 at 02:11
-
To be honest the answer can easily be found, like here: http://www.opengl.org/wiki/Creating_an_OpenGL_Context_(WGL) . Once you set this up you perform your drawing operations. – ButchDean Aug 24 '14 at 23:22
-
Also check out http://stackoverflow.com/questions/3344583/changing-glut-calls-to-work-with-mfc-c?rq=1 – ButchDean Aug 24 '14 at 23:28
-