Sign in to follow this  
adam_o

Window not updating correctly?

Recommended Posts

adam_o    137
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
adam_o    137
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
Crypter    748

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
adam_o    137
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
adam_o    137
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
Crypter    748
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
adam_o    137
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
Crypter    748
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
adam_o    137
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
Crypter    748
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
adam_o    137
Quote:
Original post by Crypter
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?


I don't know... I just stuck them in a pre-built xcode project for OGL/SDL and it did the rest... I can't help you out on that... try sticking the contents of RenderFrame() into GameLoop() and then sticking that all into whatever the main loop for whatever thing you use is... that should work...

Share this post


Link to post
Share on other sites
Eitsch    188
could you send me your xcode project zipped? (got xcode)

actually you just need to call the glClear function before you draw every frame. this function sets all pixels of the screen to you clear color definded with glClearColor.

Share this post


Link to post
Share on other sites
adam_o    137
Quote:
Original post by Eitsch
could you send me your xcode project zipped? (got xcode)

actually you just need to call the glClear function before you draw every frame. this function sets all pixels of the screen to you clear color definded with glClearColor.


MEH! ANOTHER MAC USER ON GAMEDEV!! (Eitsch ++)

Code

Share this post


Link to post
Share on other sites
ImperfectFreak    122
I can't even follow your code sorry, it compiles barely, but doesn't run at all. I am on Windows XP with MSVC++2005, I might mess with it later, but I realize that you never load the identity matrix after clearing the buffer, glLoadIdentity().

Edit: I got it to work, sort of. It turns out the resolution you had it set to was too big for my screen. Also no event handling takes place, but your problem with the update stems from all those loops you have, in one loop it goes

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);

RenderFrame();

then inside RenderFrame you have another loop, in that loop is where the clearing needs to take place.

[Edited by - ImperfectFreak on May 28, 2007 1:45:22 PM]

Share this post


Link to post
Share on other sites
adam_o    137
Quote:
Original post by ImperfectFreak
I can't even follow your code sorry, it compiles barely, but doesn't run at all. I am on Windows XP with MSVC++2005, I might mess with it later, but I realize that you never load the identity matrix after clearing the buffer, glLoadIdentity().

Edit: I got it to work, sort of. It turns out the resolution you had it set to was too big for my screen. Also no event handling takes place, but your problem with the update stems from all those loops you have, in one loop it goes

glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);

RenderFrame();

then inside RenderFrame you have another loop, in that loop is where the clearing needs to take place.

Oh yeah, I forgot to tell y'all about the resolution change. SCREENDW and SCREENDH need to be changed to your screen resolution... I think you can figure out which is which...
Ok, so I just tried your suggestion, and now the application exits with "exit code 102." Now I put this in the code to detect specific errors, and this one is in the translate() function in t_001.h . It basically means that the array that stores the values for the tetris pieces, arr_tetris_screen[][], isn't initialized or something. I'm having trouble detecting what the problem is... does anyone know what the problem is?

EDIT: Here is the most recent code, including the project files...
...this code has been removed because of updates...

[Edited by - adam_o on May 28, 2007 11:24:44 PM]

Share this post


Link to post
Share on other sites
adam_o    137
Ok, so now I've fixed the "102" problem, but now I have a different problem, and I will be unable to post the new code tonight. The old code is much different from the new stuff, so please wait for me to get the code ready...

Share this post


Link to post
Share on other sites
adam_o    137
I have been totally rewriting the structure of the code, and I don't know if it will have the same problems as the code before, but I will create a new topic if I have trouble with it. Thanks for your help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this