Window not updating correctly?

Started by
16 comments, last by adam_o 16 years, 10 months ago
In the quest for making a Tetris clone, I have run into yet another problem. For some reason, when I'm dropping my block, it doesn't clear the part above where the block was, leaving a streak effect like this: Picture Why doesn't it clean up after itself? (source code removed; see below for updated code) [Edited by - adam_o on May 5, 2007 7:18:17 PM]
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
Advertisement
Do I need to clear it and re-draw the entire scene every time I update something? Isn't that a little excessive? Or am I just not understanding this correctly? Thank you for the help!

Edit: where did that post go?
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
void GameApp::GameLoop(){    srand(time(NULL));	glClear(GL_COLOR_BUFFER_BIT);	gameinprogress = 1;			RenderFrame();    }

I see you are clearing the pixel buffer each frame, but have you
set a background color? ie glClearColor()? I dont see it in
your code.

Also, you should seed the random number generator only once when your
program terminates. Try this:
void GameApp::GameLoop(){   // srand(time(NULL));               // Put in init routine        glClearColor (0.0f,0.0f,0.0f,0.5f);	glClear(GL_COLOR_BUFFER_BIT);	gameinprogress = 1;			RenderFrame();    }


Quote:
Do I need to clear it and re-draw the entire scene every time I update something? Isn't that a little excessive? Or am I just not understanding this correctly? Thank you for the help!

No--One only needs to clear the screen/backbuffer. One should also
clear the Z buffer each frame, if it is being used.

Quote:
Edit: where did that post go?

I deleted it when I seen the link for your code. I wanted to provide
more help[smile] Also, I didnt know you were mixing SDL/OpenGL.
Hmm... I had the glClearColor function in the header file (background_data() function) so I moved it to GameLoop() as you suggested... but it still doesn't work... I have a feeling that I didn't declare enough somewhere... am I supposed to clear something else after I clear the color?

New code
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
Quote:
Quote:
Do I need to clear it and re-draw the entire scene every time I update something? Isn't that a little excessive? Or am I just not understanding this correctly? Thank you for the help!

No--One only needs to clear the screen/backbuffer. One should also
clear the Z buffer each frame, if it is being used.

Quote:
Edit: where did that post go?

I deleted it when I seen the link for your code. I wanted to provide
more help[smile] Also, I didnt know you were mixing SDL/OpenGL.


Ok, I didn't quite understand that whole clearing thing, (I'm better at understanding by looking at the code itself [smile]) so what do I need to add to my code, and where? (i.e. "add glClearColor() into the RenderFrame() function)
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
I notice you are flushing using OpenGL's buffers first, then rendering
over it. What exactally is being flushed?

void GameApp::RenderFrame(){//etc..		glFlush(); //flush buffers--we are flushing                           //previous frame contents		translate(); // render frame		cornery--;	}}


Try this:
void GameApp::RenderFrame(){//etc..           // no glFlush()		translate(); // render frame		cornery--;	}}void translate(){//etc...	show_tile();	background_data();        glFlush ();	SDL_GL_SwapBuffers();}


I use OpenGL (Not SDL), but this might be the problem.

Quote:
Ok, I didn't quite understand that whole clearing thing,

What I mean is clearing both the color and z buffer:
glClear (GL_COLOR_BUFFER|GL_DEPTH_BUFFER);

Quote:Original post by Crypter
I notice you are flushing using OpenGL's buffers first, then rendering
over it. What exactally is being flushed?

void GameApp::RenderFrame(){//etc..		glFlush(); //flush buffers--we are flushing                           //previous frame contents		translate(); // render frame		cornery--;	}}


Try this:
*** Source Snippet Removed ***

I use OpenGL (Not SDL), but this might be the problem.

Quote:
Ok, I didn't quite understand that whole clearing thing,

What I mean is clearing both the color and z buffer:
glClear (GL_COLOR_BUFFER|GL_DEPTH_BUFFER);


Thank you for clearing that up. Since I'm using gluOrtho2D(), I don't need to deal with the z buffer, though... but thank you for the update on the location of glFlush().

Unfortunately, it still does not work. [sad]
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
I just set up SDL, but am having some difficaulties setting the
project properties correctly (As stated before, I never used SDL :) )

(The problem Im having is that SDL routines are executing, but all routines
fail)

If you can upload your project file, Ill see if I can debug it.
Quote:Original post by Crypter
I just set up SDL, but am having some difficaulties setting the
project properties correctly (As stated before, I never used SDL :) )

(The problem Im having is that SDL routines are executing, but all routines
fail)

If you can upload your project file, Ill see if I can debug it.


Do you use a Mac? Because otherwise, it won't work...
_______________________My computer stats:Xcode 3.1.2Mac OS 10.5.8---Visual C++ 2008 Express EditionWindows XP---NetBeansUbuntu 9.04---Help needed here!
Quote:
Do you use a Mac? Because otherwise, it won't work...

Sorry-nope. (I use MSVC++ 8 on WinXP SP2)

Coinsidering OpenGL/SDL are portable, Can you tell me the
project configuations?

This topic is closed to new replies.

Advertisement