OpenGL/C confusion - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL/C confusion (/thread-3400.html)
OpenGL/C confusion - spsweet - Mar 21, 2007 04:22 PM
I'm pretty new to OpenGL and would like clearing up from you guys who have been doing this sort of thing for a while. I do have a few years of experience with other languages, but this small problem is making me feel stupid.
The situation is that I'm trying to just make a real time animation using OpenGL and C. I've got a nice model in 3D space and want to enter the infinite loop to make it keep rotating. I can make it rotate with the modelview matrix, but only on keyboard input. I want it to keep going. I know this sounds like a stupid question but I couldn't find anything in the many other places I've looked. As good as the Red Book is, it didn't have a straightforward answer for me. If anyone's willing to help, I'll start posting code upon your command.
OpenGL/C confusion - OneSadCookie - Mar 21, 2007 04:23 PM
This isn't an OpenGL question as such... What windowing API are you using? SDL? GLUT? Carbon? Cocoa?
OpenGL/C confusion - spsweet - Mar 21, 2007 04:28 PM
GLUT. I am also unfortunately not using MAC. I'm using a Linux machine. I believe there is a concept I don't understand and that is what I hope someone can explain to me.
OpenGL/C confusion - Fenris - Mar 21, 2007 04:39 PM
You're likely missing glutPostRedisplay() in your idle() function.
OpenGL/C confusion - spsweet - Mar 21, 2007 04:42 PM
Perhaps a bit more clarity is in order. I am in fact using GLUT. What I want is something basic. I want a figure, lets say a cylinder, to rotate on an axis, how about the y axis, without me having to push anything to make the display function be invoked again. I tried things like glutIdleFunc(display); hoping that if input was idle, display would be called. And when that didn't work I went back to the drawing board. I see a lot of things about rotating over time but don't see how to do it. My ultimate goal is to just have my model rotate and be able to rotate it faster and faster using the modeview matrix and a call to glRotate(yRot,x,y,z);
I hope that makes someone want to explain it to me better.
edit:I just tried a new function for being idle called, is_idle. And made that my parameter to glutIdleFunc(). Within is_idle was a single line to call glutPostRedisplay(). It didn't work as I expected. I did however get what I wanted when I put a glutPostRedisplay() at the end of my display function. This seems like a crude method but it definitely worked. Any other suggestions guys?
OpenGL/C confusion - OneSadCookie - Mar 21, 2007 05:46 PM
the usual way is as you describe:
Putting it at the end of display should work fine too, though.
OpenGL/C confusion - spsweet - Mar 21, 2007 06:17 PM
thanks guys. the problem was that I didn't tell my display function that is_idle is my idle function. For some reason I had to tell display as well as main and not just main like I had been doing. thanks for the help guys.
OpenGL/C confusion - OneSadCookie - Mar 21, 2007 06:54 PM
You only have to make that call once, in main. Doing it more often than that might cause peculiar things to happen, I guess.
Basic GLUT skeleton code here: http://onesadcookie.com/Tutorials (and yes, I have tried it on Linux; only the #include needs to change)