Sign in to follow this  
ProgrammerZ

Calling BeginScene and EndScene slows down my program . . . help!

Recommended Posts

Hey guys. I finally finished my renderer class, so I immediately started playing around with it, of course. However, I noticed that my window was a little slow -- it took a second to drag it around, and when I moused over the close button (xp) it took a second to highlight it. I also tried drawing a sprite at the location of the mouse cursor, but it was terribly jerky and lagged behind a lot, and if I pushed keys at the same time, it would follow along the trail my cursor had left a few seconds ago. Also, I did a simple check to see if my frame rate was normal (rendering a sprite every other frame) and it was. It's like my message queue is on a delay. However, I noticed that if I didn't call BeginScene and EndScene (and didn't do any rendering) my window was completely responsive. Does anyone know what my problem could be? -- ProgrammerZ

Share this post


Link to post
Share on other sites
I work with Delphi (You didn't mention what your IDE is), but I think that the problem has to do with this (it happened to me at first):

You should always check in your main loop (either yours or from your IDE) the immediate response to messages dispatched from the operating system.

That is, make sure to verify after each BeginScene ... EndScene block if there is a message queued and then immediately process it (for example, messages related to the mouse or keyboard).

[Edited by - jpventoso on September 16, 2008 12:59:21 AM]

Share this post


Link to post
Share on other sites
Are you completely pumping the message loop every frame? It's a common mistake to only process one message per frame, and this causes the message queue to become backed up. Your main loop should look something like this:


// main game loop
while (gameIsRunning)
{
// loop until the message queue is empty
MESSAGE msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
DispatchMessage(&msg);
}

Update(); // Update game logic
Render(); // Render everything
}


Share this post


Link to post
Share on other sites
[quote]Original post by MJP
Are you completely pumping the message loop every frame?[quote]
Oh. Duh. (kicks self)

Anyway, I changed an
if
to a
while
in my message processing code, and it works like a charm. Thanks! I guess I hadn't noticed that mistake when I was coding that part.

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