I am working on an OpenGL Shader Engine from www.MarekKnows.com and the framework is setup as follows: An Engine Class that is part of a static library with other helpful and important classes. Then there is the main startup project where the Game Class resides along with Game Properties. This structure is to keep all Engine code separate from Game code. The nice thing about this setup is it can be reused to create a variety of games just by inheriting from the Engine lib. It is not complete as of yet as each week another segment or class object is being incorporated.
This hierarchy is based on the folder & VS filter structure:
Project - Static Lib Engine
Start Up Project - Game
- Game: Inherits from Engine
- Properties: - Properties unique to current game
With this frame work I'll demonstrate the message loop for you
void Engine::start() {
while( true ) {
if ( PeekMessage( &m_msg, m_hWnd, 0, 0, PM_REMOVE ) ) {
if ( WM_QUIT == m_msg.message ) {
break;
} else {
TranslateMessage( &m_msg );
DispatchMessage( &m_msg );
}
} else {
processFrame();
}
}
}
If you would like to see more of this code then you will have to visit www.MarekKnows.com for his wonderfully well structured and clearly explained video tutorials for Game Development using OpenGL. For copy right reasons I will only give small snippets as suggestions to others that may help them with a specific case problem. I can not claim this as my own source code, however with following his course setup everything is personally hand typed and personally debugged. There is no copying and pasting! Almost everything I have learned about Game Programming is accredited to Marek's videos along with a few other sources.
I can try to explain this the best I can from what I have learned and following the code's execution. Somewhere in the program the Engine::start() function is invoked. The first thing that happens is we go into an infinite while loop;
within this while loop we check to see if any messages from windows were peeked and if they are we check to see if the WM_QUIT message was set from some other place. If it was set we break out of the while loop and return from this function and the application will clean up memory, destroy window and close; otherwise we then call TranslateMessage() & DispatchMessage(). If the PeekMessage() returns false then we go into the else statement and call proccessFrame().
On my machine I am rending basic GUI objects at about 100-120 frames per second with this framework. I have an EVGA NVidia GeForce GTX 750Ti 2GB with overclocking and dual fan coolant running on Windows 7 64bit with 8GB Ram on an Intel Core 2 Quad Extreme 3.0Ghz.
We have not yet delved into extensive animations, physics, particles systems, collision detections as of yet. We did however cover all of that in one of his older video series were the older GameEngine was based on OpenGL v1.0 and everything was done on the CPU. With this series we are now working on using Shaders & the GPU. I am sure with this frame work we can have a full 2D or 3D game running on a system similar to mine at a full 40 - 60 FPS with ease.
Another great source for learning is to check out www.GeometricTools.com and check out the book section. A few years ago I purchased their book: 3D Game Engine Design (2nd Edition) by David H. Eberly, The Morgan Kaufmann Series in Interactive 3D Technology, and it is a great read. I have not yet had the chance to purchase their newest book: GPGPU Programming for Games and Science
by David H. Eberly, but would soon like to own it since it is more relevant, current and up to date with modern hardware & software development. Good luck to you!