I am writing an OpenGL renderer and I have found an unusual problem... the window is only updated when windows needs to send a message (i.e. mouse movement/press and key presses). I am using a windows wrapper class with a message router. I will include the relavant code below:
Windows Wrapper Functions:
/*****************************************************************************
CWND::MainLoop()
Window''s main loop that receives and translates messages as well as calling
the window''s main logic loop.
*****************************************************************************/
LRESULT CWND::MainLoop()
{
// Main message loop
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
// Translate & dispatch to even quene
TranslateMessage(&msg);
DispatchMessage(&msg);
// Main game logic cycle
GameCycle(this);
}
}
/*****************************************************************************
CWND::MessageRouter(HWND, UINT, WPARAM, LPARAM)
Routes a message to the correct class instance (static)
*****************************************************************************/
LRESULT CALLBACK CWND::MessageRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
CWND *p_wnd = 0;
if(msg == WM_NCCREATE)
{
// retrieve Window instance from window creation data and associate
LPCREATESTRUCT cs = reinterpret_cast<LPCREATESTRUCT>(lParam);
SetWindowLong(hwnd, GWL_USERDATA, (long)(cs->lpCreateParams));
// retrieve associated Window instance
p_wnd = reinterpret_cast<CWND*>(GetWindowLong(hwnd, GWL_USERDATA));
// save window handle
if(p_wnd)
{
p_wnd->SetHWND(hwnd);
}
}
else
{
// retrieve associated Window instance
p_wnd = reinterpret_cast<CWND*>(GetWindowLong(hwnd, GWL_USERDATA));
}
if(p_wnd)
{
// retrieve the associated message handler
t_messageIterator i = p_wnd->GetMessageHandler(msg);
// test iterator for validity
if(i != p_wnd->GetEndItr())
return (i->second)(p_wnd, hwnd, wParam, lParam);
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
Program Main loop:
int WINAPI WinMain(HINSTANCE instance, HINSTANCE PrevInstance, LPSTR cmdLine,
int showCmd)
{
// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL, "Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",
MB_YESNO | MB_ICONQUESTION) == IDNO)
{
g_fullscreen = false; // Windowed Mode
}
// initialize the timer
if(!g_timer.Init())
{ MessageBox(NULL, "Timer not supported", "ERROR", MB_OK); }
// construct the class
COGLWND *p_window = new COGLWND("A Window", 800, 600, 32, g_fullscreen, GameCycle);
// Create a window
p_window->CreateWnd(showCmd, instance);
// register the message handlers
p_window->RegisterDefaultHandlers();
// Setup the pixel format
p_window->InitPixelFormat(32);
// enable openGL
p_window->EnableOGL();
p_window->InitOGL();
p_window->CreateBitmapFont("Impact", 30);
// Enter the window''s main loop
p_window->MainLoop();
// clean up
p_window->ClearFont(0);
delete p_window;
p_window = NULL;
}
NOTE: The main loop is sloppy I know... its only temporary