bobo1on1 Wrote:Can you give a link to the code you're trying to port?
The code is gears.c here:
http://www.opengl.org/resources/code/sam...demos.html
Since I've made further progress, let me go into some more detail--
In Start(), I'm doing this:
Code:
glPushAttrib(GL_ALL_ATTRIB_BITS);
init(); // copied from gears.c; calls gear(...) also from gears.c
This sets some OpenGL state and builds the display lists for the three gear objects.
In Render():
Code:
updateAngle(); // my own small function to make the gears rotate
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glFrustum( ... );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, 0.0, -40.0);
draw(); // from gears.c, but glutSwapBuffers() changed to glFlush()
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
And in Stop():
This actually works (yay!), but leaves some nagging questions:
If I don't include the glPushAttrib() and glPopAttrib() calls, then when the screensaver is stopped, XBMC shows only black screens. It responds to keyboard & mouse, so isn't hung, but its ability to show anything is messed up.
But doing glPushAttrib() in Start() and glPopAttrib() in Stop() seems risky. Assume XBMC someday does:
Code:
glPushAttrib( ... );
pScreensaver->Start();
glPopAttrib();
Then things can get weird. In other words, I'm not guaranteed that
Code:
Start();
while (...) Render();
Stop();
isn't interleaved with XBMC's own calls to change OpenGL state, push/pop attributes, etc.
On the other hand, pushing all the attributes, setting them the way I need them, drawing my screen, and popping all the attributes every time that Render() is called would be nice to avoid if it isn't necessary. In fact, I think that popping all the attributes would release by display lists, and setting those up really should only have to happen once.
But if the rule is that the OpenGL state upon each entry to Render() is arbitrary and must always be set up completely each time, then that would be good to know and document.
A similar but less intrusive questions comes with the projection and modelview matrices. Even if my screensaver is running, I notice that XBMC changes these matrices between calling Start() and calling Render(). At the very least whatever it's doing seems unnecessary since the screensaver occupies the entire screen.
Any input appreciated.