27 int WINAPI
WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow ) {
31 ret = app->main( hInstance, hPrevInstance, lpCmdLine, nCmdShow );
34 MessageBox( HWND_DESKTOP,
"Error Creating Application Class",
"Error", MB_OK | MB_ICONEXCLAMATION );
49 LRESULT CALLBACK
WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
50 LONG userData = GetWindowLong(hWnd, GWL_USERDATA);
51 if ( userData == 0 ) {
52 if ( uMsg == WM_CREATE ) {
54 CREATESTRUCT * creation =
reinterpret_cast<CREATESTRUCT *
>( lParam );
58 SetWindowLong( hWnd, GWL_USERDATA, reinterpret_cast<LONG>(app) );
59 app->m_isVisible =
true;
64 return app->message( hWnd, uMsg, wParam, lParam );
66 return DefWindowProc( hWnd, uMsg, wParam, lParam );
81 m_className = className;
82 m_isProgramLooping =
true;
83 m_createFullScreen =
true;
88 useFrameLimit =
false;
117 glDisable( GL_CULL_FACE );
118 glDisable( GL_DEPTH_TEST );
119 glDisable( GL_LIGHTING );
120 glDisable( GL_LIGHT0 );
127 glEnable( GL_DEPTH_TEST );
128 glEnable( GL_CULL_FACE );
129 glEnable( GL_LIGHTING );
130 glEnable( GL_LIGHT0 );
153 return this->useFrameLimit ? m_frameLimit : 0;
180 PostMessage( m_window, WM_QUIT, 0, 0 );
181 m_isProgramLooping =
false;
188 PostMessage(m_window, WM_TOGGLEFULLSCREEN, 0, 0);
198 LRESULT OpenGLApplication::message( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
203 case SC_MONITORPOWER:
212 case WM_EXITMENULOOP:
213 case WM_EXITSIZEMOVE:
218 m_window.
setLeft( LOWORD(lParam) );
219 m_window.
setTop( HIWORD(lParam) );
231 RECT * rect = (RECT *)lParam;
232 m_window.
setWidth( rect->right - rect->left );
233 m_window.
setHeight( rect->bottom - rect->top );
249 m_window.
setWidth( LOWORD(lParam) );
259 m_window.
keyDown( (
unsigned char)wParam );
263 m_window.
keyUp( (
unsigned char)wParam );
280 case WM_TOGGLEFULLSCREEN:
281 m_createFullScreen = !m_createFullScreen;
282 PostMessage( hWnd, WM_QUIT, 0, 0 );
286 return DefWindowProc( hWnd, uMsg, wParam, lParam );
302 int OpenGLApplication::main( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
int nCmdShow ) {
305 ZeroMemory( &wc,
sizeof(wc) );
307 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
308 wc.lpfnWndProc = (WNDPROC)
WndProc;
309 wc.hInstance = hInstance;
311 wc.hIcon = LoadIcon( NULL, IDI_WINLOGO );
312 wc.hCursor = LoadCursor( NULL, IDC_ARROW );
313 wc.lpszClassName = m_className;
315 if( !RegisterClass(&wc) ) {
316 MessageBox( NULL,
"Failed to register the Window-Class.",
"ERROR", MB_OK | MB_ICONEXCLAMATION );
322 while( m_isProgramLooping ) {
323 bool result = m_window.
create(
"mElite - Grafica al Calcolatore Progetto da Melanie und Jan-Philipp", m_createFullScreen, m_className, hInstance,
this );
330 bool isMessagePumpActive =
true;
332 while( isMessagePumpActive ) {
333 if( PeekMessage( &msg, m_window, 0, 0, PM_REMOVE ) != 0) {
334 if ( msg.message != WM_QUIT ) {
335 DispatchMessage( &msg );
337 isMessagePumpActive =
false;
340 if (m_isVisible ==
false) {
351 MessageBox(HWND_DESKTOP,
"Error creating OpenGL Window",
"Error", MB_OK | MB_ICONEXCLAMATION);
352 m_isProgramLooping =
false;
356 if( !UnregisterClass( m_className, hInstance ) ) {
357 MessageBox( NULL,
"Could not unregister Window-Class.",
"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION );
370 if(framesPerSecond == 0)
371 useFrameLimit =
false;
373 useFrameLimit =
true;
374 m_frameLimit = framesPerSecond;
375 this->frameTime = 1000.0 / framesPerSecond;
383 void OpenGLApplication::drawTest() {