glEnable( GL_DEPTH_TEST );
glEnable( GL_TEXTURE_2D );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClearDepth( 1.0f );
glDepthFunc( GL_LEQUAL );
glClear problem
At the moment, the only things in the main loop in my program (other than message pumping) are glClear and glLoadIdentity, to clear the color and depth buffers. Ever since I added these lines, the program has been taking around 1.5 seconds just to complete a single loop, and it doesn't even clear the screen. Has this happened to anyone else?
Here is some of my initialization code:
This code comes before any other OpenGL code. Following is window creation code, then glViewport, then glOrtho, then the loop begins. I'm not sure whether the order of initialization makes a difference. Thanks in advance.
[Edited by - Daggerbot on May 27, 2008 11:32:22 PM]
Those few lines are probably not the source of the problem. I'm afraid you have to provide more info. Could you post the initialization and main loop code?
Thanks for the reply. Here's a bit of the code:
// initialize OpenGLvoid InitGL(){ if( g_gl_init ) return; else g_gl_init = true; glEnable( GL_DEPTH_TEST ); glEnable( GL_TEXTURE_2D ); glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); glClearDepth( 1.0f ); glDepthFunc( GL_LEQUAL );}
// initialize windowbool TV_GameWindow::SetGameMode( Dimsu &size, bool full_screen ){#define END { EndGameMode(); return false; } _TV_GameWindow *ws = (_TV_GameWindow*) m_handle; InitGL(); if( ws->hwnd ) DestroyWindow( ws->hwnd ); // create window ws->hwnd = CreateGameWindow( *m_text, size.width, size.height, full_screen ); if( !ws->hwnd ) return false; // associate window SetWindowLongW( ws->hwnd, 0, 1 ); if( !SetWindowLongW( ws->hwnd, 0, (LONG) this ) ) END // rendering context GLuint pf; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0 }; if( !( ws->hdc = GetDC( ws->hwnd ) ) ) END if( !( pf = ChoosePixelFormat( ws->hdc, &pfd ) ) ) END if( !SetPixelFormat( ws->hdc, pf, &pfd ) ) END if( !( ws->hrc = wglCreateContext( ws->hdc ) ) ) END // finish Show( IsWindowVisible( ws->hwnd ) == TRUE ); return true;#undef END}
// setup rendering planevoid TV_GameWindow::SelectSurface(){ wglMakeCurrent( ((_TV_GameWindow*)m_handle)->hdc, ((_TV_GameWindow*)m_handle)->hrc );}void TV_SelectSurface( TV_GameWindow *window ){ window->SelectSurface();}void TV_SelectViewport( const Rect &viewport ){ glViewport( viewport.left, viewport.top, viewport.right - viewport.left, viewport.bottom - viewport.top );}void TV_SelectPlane( const Dims &size, double znear, double zfar ){ glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0.0, size.width, size.height, 0.0, znear, zfar ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity();}
// mainbool TC_PumpInput(){ MSG msg; if( PeekMessageW( &msg, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); if( msg.message == WM_QUIT ) return false; else DispatchMessageW( &msg ); } return true;}void TV_ClearAll(){ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity();}int WINAPI WinMain( HINSTANCE inst, HINSTANCE prev_inst, char *cmd_line, int show_cmd ){ // coords Dimsu size = { 640, 480 }; Rect viewport = { 0, 0, 640, 480 }; Dims plane = { 640, 480 }; // init TC_InitInput(); TV_GameWindow *window = new TV_GameWindow( L"test", size, false ); if( !window->IsValid() ) { MessageBoxW( NULL, L"Can't create game window!", NULL, MB_OK ); return 1; } TV_SelectSurface( window ); TV_SelectViewport( viewport ); TV_SelectPlane( plane, 0.0, 1.0 ); // run window->Show(); while( TC_PumpInput() ) { TV_ClearAll(); } // end delete window; return 0;}
think you need to swap the back buffer, with
SwapBuffers(hdc); where hdc is the handle to the device context that you created.
SwapBuffers(hdc); where hdc is the handle to the device context that you created.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement