PDA

View Full Version : Loop message and the eternal C vs. C++ question.



Anonymous Coward
08-25-2000, 12:38 PM
Can any of you tell me of an efficient Windows loop message for use with OpenGL, and tell me why is efficient?
Another thing, Im doing a little demo using C (structs and no classes). While programming for an OpenGL app. is there some preference between C and C++?

poop on a stick
08-25-2000, 01:32 PM
i don't really understand what you mean by efficient windows loop message but I think you mean:

if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Drawing & logic code here
glFlush();
InvalidateRect(hwnd,NULL,FALSE); //I think those parameters are correct?!?

By the way PeekMessage(...) is more efficient than GetMessage(...) because it doesn't sit and wait for a message to be queued.

[This message has been edited by poop on a stick (edited 08-25-2000).]

skippyj777
08-25-2000, 02:12 PM
The above code only processes 1 single message before drawing. It is better to process all of the window's messages before drawing, as more than one message can accumulate in a window's msg queue while the app is drawing and processing data. Use a "while" loop instead of an "if" statement with the PeekMessage function. BTW, Mr. Stick, why does your loop not check to see if the window was destroyed?

foobar
08-30-2000, 08:44 AM
do {

if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
} else {
/*UPDATE()+DRAW()*/
}

} while( WM_QUIT != msg.message );


This is the msg loop I use - it basically hogs as much of windows resources as possible (if you want to call that efficient). If there are messages it processes them and when it has emptiedthe message queue it does the application programming, leaving no idle time for other programs. If you have multiple windows etc in your app this wont be very good but for something like a game it works a treat http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by foobar (edited 08-30-2000).]

Anonymous Coward
08-31-2000, 08:38 AM
Ok. I made a little program with an OpenGL window and a little console (a Windows dialog box). If I click on the dialog to move the window I noticed that the OpenGL window stop drawing stuff, how can I fix that?