GLWindow
GLWindow()
The constructor consists of simple initialization. Fairly self explanatory.
GLWindow::GLWindow()
{
strncpy(title, "OpenGL", 7);
starting_width = 512; current_width = 512;
starting_height = 512; current_height = 512;
bitsPerPixel = 32;
isFullScreen = false;
}
~GLWindow()
The destructor is empty.
GLWindow::~GLWindow(void)
{
}
void GLWindow::mainLoop(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
mainLoop is the hardcore worker. It handles all creations and drives the update-draw loop. If you really want to know how it works, look up NeHe and MSDN, they’ll explain it to you far better than I ever could.
void
GLWindow::mainLoop(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
strncpy(className, "OpenGL", 7);
this->hInstance = hInstance;
memset(keys, false, sizeof(char) * 256);
if(registerWindowClass() == false)
{
// Failure
MessageBox(HWND_DESKTOP, "Error Registering Window Class!", "Error", MB_OK | MB_ICONEXCLAMATION);
return;
}
isProgramLooping = true;
createFullscreen = isFullScreen;
while(isProgramLooping) // Loop Until WM_QUIT Is Received
{
// Create A Window
isFullScreen = createFullscreen;
if(createWindow() == true)
{
// At This Point We Should Have A Window That Is Setup To Render OpenGL
if(init() == false) // Call User Intialization
{
// Failure
terminateApplication();
}
else
{
isMessagePumpActive = true; // Set isMessagePumpActive To TRUE
while(isMessagePumpActive == true) // While The Message Pump Is Active
{
// Success Creating Window. Check For Window Messages
if(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) != 0)
{
if(msg.message != WM_QUIT)
{
DispatchMessage(&msg);
}
else
{
isMessagePumpActive = false;
}
}
else
{
if(isVisible == false)
{
WaitMessage(); // Application Is Minimized Wait For A Message
}
else
{
DWORD tickCount = GetTickCount(); // Get The Tick Count
update(tickCount - lastTickCount); // Update The Counter
lastTickCount = tickCount; // Set Last Count To Current Count
draw(); // Draw Our Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}
} // Loop While isMessagePumpActive == TRUE
} // If (Initialize (...
// Application Is Finished
deinit(); // User Defined DeInitialization
destroyWindow(); // Destroy The Active Window
}
else // If Window Creation Failed
{
// Error Creating Window
MessageBox(HWND_DESKTOP, "Error Creating OpenGL Window", "Error", MB_OK | MB_ICONEXCLAMATION);
isProgramLooping = false;
}
} // While (isProgramLooping)
UnregisterClass(className, hInstance); // UnRegister Window Class
return;
}