Possible to not clear the color buffer to keep info?

Started by
4 comments, last by ShDragon 20 years, 2 months ago
I''m trying to display an image that is being dynamically created at runtime that is considerably too complex to be generated once every 1/60th of a second. (Its about a jillion grRectf()s all composed together) I tried a single buffer and not calling glClear() in hopes that I could just keep adding to the frame until it was done, but no dice. I just get a black screen. The basic question really is: Is there a way to get this to work: while(1) { handle_events(); draw_a_little_bit(); } instead of: while(1) { handle_events(); draw_everything(); } If not, any suggestions on other ways of getting an incredibly complex, runtime created image onto the screen? Dynamically created texture data maybe?
Advertisement
quote:Original post by ShDragon
I tried a single buffer and not calling glClear() in hopes that I could just keep adding to the frame until it was done, but no dice. I just get a black screen.


That method should work. Could you post the relevant parts of your window creation code and drawing code?

Enigma
I'm using SDL to create the OpenGL window, and it works as long as I draw something every time through the event loop. Here's the code (with the error checking stuff taken out.) For testing purposes, right now all I have is one rect being drawn before the event loop begins. I figure, if I can get one rect to show up, I can get as many as I want.

main() {   const SDL_VideoInfo *info = NULL;      SDL_Init(SDL_INIT_VIDEO)   info = SDL_GetVideoInfo( );      SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );     // atleast 5 bits of red...   SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );   // and 5 bits of green.   SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );    // and 5 bits of red   SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 0 ); // Non double buffered window         SDL_SetVideoMode(WIDTH, HEIGHT, info->vfmt->BitsPerPixel, SDL_OPENGL|SDL_FULLSCREEN);      SDL_ShowCursor(0);             // hide the mouse   SDL_WM_GrabInput(SDL_GRAB_ON); // and grab it      // Set up OpenGL   float ratio = (float) WIDTH / (float) HEIGHT;   glShadeModel( GL_FLAT );                                   // flat shading   //glCullFace( GL_BACK );                                     // don't draw the backs of polys   glFrontFace( GL_CCW );                                     // ccw is front   //glEnable( GL_CULL_FACE );                                  // don't bother with backwards polys.   //glEnable( GL_TEXTURE_2D );	                               // enable 2D textures   glClearColor( 0, 0, 0, 0 );                                // clear color = black   glViewport( 0, 0, (GLsizei)WIDTH, (GLsizei)HEIGHT );                         // set viewport (0,0) is lower left   glMatrixMode( GL_PROJECTION );                             // set projection matrix.   glLoadIdentity( );                                         // clear projection matrix   gluOrtho2D( 0.0, (GLdouble)WIDTH, 0.0, (GLdouble)HEIGHT ); // 2d ortho projection, with (0,0) in bottom left.   glMatrixMode( GL_MODELVIEW );   glLoadIdentity( );      glClear( GL_COLOR_BUFFER_BIT );   glColor3f(1.0f, 1.0f, 1.0f);   glRectf(-25.0, -25.0, 25.0, 25.0);      while(1) { /* blah */ }}



[edited by - ShDragon on February 8, 2004 6:41:22 PM]

[edited by - ShDragon on February 8, 2004 6:42:10 PM]
While playing around, I discovered something interesting... If I make a countdown variable and decrement that each time through the event loop and draw a rect when it reaches zero, then -never draw the rect again-, the rect stays on the screen.
Its like the rect before the event loop is being drawn too fast and is somehow getting caught in the glClear() that comes before it.

This works:
   int tillDrawn = 5;      while(1)   {      if( SDL_PollEvent(&Event) != 0 )      {         /* handle events */      }      else      {         if( tillDrawn == 0 )         {            glColor3f(1.0f, 1.0f, 1.0f);            glRectf(-25.0, -25.0, 25.0, 25.0);         }         else if( tillDrawn > -5 ) tillDrawn --;      }   }

but if the rect is before the while() (or drawn only the first time through the loop, instead of the 5th) it doesn't ever show.


Edit: fixed the source code to make sure tillDrawn decrements below zero. It now decrements down to -4, so the rect is only drawn once. The behavior of the program is still the same: the rect stays on the screen once drawn.

[edited by - ShDragon on February 8, 2004 8:34:26 PM]
Try adding a glFlush() after the glRect calls.
GlFlush made it work.

Then going back to my original program, it decided not to work again. More poking around put the blame on my glColor3i() call. I rescaled my color information into floats and used glColor3f() instead and it works like a charm.

Thank you all for your help. I hope I can actually start answering questions someday soon.

This topic is closed to new replies.

Advertisement