Jump to content
  • Advertisement
Sign in to follow this  
adam_o

Window not updating correctly?

This topic is 4035 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!