Thread: [Plib-users] Newbie Question: Mixing SSG & OpenGL
Brought to you by:
sjbaker
From: Stanford N. <st...@th...> - 2002-05-09 17:59:52
|
Hi everyone! I just got started with Plib and I like it a lot! Great work, guys! I'm stuck with a rather embarrassing problem: I can't seem to mix SSG & my OpenGL code together. My SSG code loads a model and displays it. My OpenGL code draws some colored polys to the screen. They both work individually, but I can't mix and match... It seems that the ssgInit() call will setup some GL state that causes the GL calls in my custom code to not render... This is rather perplexing as I have managed to work the 2-d font rendering via an 2-d orthogonal projection into the code. Is this something obvious I'm missing? If someone could point me to an example that has both SSG & OpenGL code working together, I'm sure I can figure out what I'm doing wrong. Thanks in advance! -- stan c",) |
From: Steve B. <sjb...@ai...> - 2002-05-09 22:05:42
|
Stanford Ng wrote: > > Hi everyone! I just got started with Plib and I like it a lot! Great > work, guys! > > I'm stuck with a rather embarrassing problem: I can't seem to mix SSG & > my OpenGL code together. My SSG code loads a model and displays it. My > OpenGL code draws some colored polys to the screen. They both work > individually, but I can't mix and match... > > It seems that the ssgInit() call will setup some GL state that causes > the GL calls in my custom code to not render... This is rather > perplexing as I have managed to work the 2-d font rendering via an 2-d > orthogonal projection into the code. Is this something obvious I'm > missing? > > If someone could point me to an example that has both SSG & OpenGL code > working together, I'm sure I can figure out what I'm doing wrong. Well, all of my games do - so check out TuxKart for example. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Stanford N. <st...@th...> - 2002-05-15 12:59:05
|
Thanks for the pointers! After much digging under the hood of my program, I'm still encountering problems with mixing SSG & OpenGL. I've narrowed it down to the ssgCullAndDraw() call influencing the GL state somehow. When I comment out ssgCullAndDraw() in my redraw routine, the draw_water() works fine, drawing a blue rectangle. When I leave the call in there, the rectangle is still drawn, but it is very dark and blends right into the background. I'm trying to puzzle out what ssgCullAndDraw() is doing that would affect the standard OpenGL stuff... I'm still quite a novice when it comes to these things. If someone could explain things, I'd much appreciate it! Thanks in advance! -- stan << CODE SNIPPETS FOR REFERENCE >> void redraw() { update_game() ; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); ssgCullAndDraw( scene ); draw_water(); draw_text(); glutPostRedisplay(); glutSwapBuffers(); } void draw_water() { glMatrixMode( GL_PROJECTION ); glPushMatrix(); glLoadIdentity(); glMatrixMode( GL_MODELVIEW ); glPushMatrix(); glLoadIdentity(); GLfloat lmodel_ambient[] = { 0.8, 0.8, 0.8, 1.0 }; glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lmodel_ambient ); glColor3f( 0.0f, 0.0f, 1.0f ); glBegin( GL_QUADS ); glVertex3f( 0.3f, 0.3f, 0.0f ); glVertex3f( -0.3f, 0.3f, 0.0f ); glVertex3f( -0.3f, -0.3f, 0.0f ); glVertex3f( 0.3f, -0.3f, 0.0f ); glEnd(); glPopMatrix(); glMatrixMode( GL_PROJECTION ); glPopMatrix(); } -----Original Message----- From: steve [mailto:steve] On Behalf Of Steve Baker Sent: Friday, May 10, 2002 2:07 PM To: Stanford Ng Cc: pli...@li... Subject: Re: [Plib-users] Newbie Question: Mixing SSG & OpenGL Stanford Ng wrote: > > Hi everyone! I just got started with Plib and I like it a lot! Great > work, guys! > > I'm stuck with a rather embarrassing problem: I can't seem to mix SSG > & my OpenGL code together. My SSG code loads a model and displays it. > My OpenGL code draws some colored polys to the screen. They both work > individually, but I can't mix and match... > > It seems that the ssgInit() call will setup some GL state that causes > the GL calls in my custom code to not render... This is rather > perplexing as I have managed to work the 2-d font rendering via an 2-d > orthogonal projection into the code. Is this something obvious I'm > missing? > > If someone could point me to an example that has both SSG & OpenGL > code working together, I'm sure I can figure out what I'm doing wrong. Well, all of my games do - so check out TuxKart for example. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |
From: Steve B. <sjb...@ai...> - 2002-05-15 13:09:07
|
Stanford Ng wrote: > After much digging under the hood of my program, I'm still encountering > problems with mixing SSG & OpenGL. I've narrowed it down to the > ssgCullAndDraw() call influencing the GL state somehow. It does change state without restoring it - yes. That's not accidental though - it's very inefficient in OpenGL to keep setting and restoring state unnecessarily - so we leave it to the application to save and restore state if it wishes to. Many applications (all of mine) get away without doing that and are faster as a result, others can do things like not restoring all of the detailed texture attributes because they just glDisable texture globally. So, it's better to let the application decide. > When I comment > out ssgCullAndDraw() in my redraw routine, the draw_water() works fine, > drawing a blue rectangle. When I leave the call in there, the rectangle > is still drawn, but it is very dark and blends right into the > background. > > I'm trying to puzzle out what ssgCullAndDraw() is doing that would > affect the standard OpenGL stuff... I'm still quite a novice when it > comes to these things. If someone could explain things, I'd much > appreciate it! Thanks in advance! As a first shot at fixing this, you could wrap ssgCullAndDraw with glPushAttrib ( GL_ALL_ATTRIB_BITS ) ; ssgCullAndDraw () ; glPopAttrib () ; ...that will almost certainly fix your problem - but at some performance cost. If you find that cost is acceptable - then you're done. If not then you'll have to ascertain which things that SSG changed are not acceptable to your draw_water() function. ----------------------------- Steve Baker ------------------------------- Mail : <sjb...@ai...> WorkMail: <sj...@li...> URLs : http://www.sjbaker.org http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net http://prettypoly.sf.net http://freeglut.sf.net http://toobular.sf.net http://lodestone.sf.net |