So basically I am working on an EXTREMELY basic OpenGL program. All i want it to do is clear the screen blue going through my pipeline. Now I have my HDC and HGLRC all set up and not NULL. Glew doesn't throw any errors, Set and ChoosePixelFormat have no problems, and wglCreateContext and wglMakeCurrent both work without throwing any errors. But when the game starts calling glClear, the entire game freezes up. The message pump is still running, and if I step through it, I'm still receiving WM_PAINT messages. The system will still respond, but its really slow, like ten to forty-five seconds slow. I'm posting all relevant code
This is my window set up
// Create a window
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wcex.lpfnWndProc = (WNDPROC)MainWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = (HCURSOR)LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("Thunderclad Engine"); // Should be unique
wcex.hIconSm = NULL;
// Select window styles
UINT unStyle,unStyleX;
unStyleX = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
unStyle = WS_OVERLAPPEDWINDOW;
// Describe our window placement
WINDOWPLACEMENT wndPlacement;
wndPlacement.length = sizeof(WINDOWPLACEMENT);
wndPlacement.ptMaxPosition.x = 0;
wndPlacement.ptMaxPosition.y = 0;
wndPlacement.ptMinPosition.x = 0;
wndPlacement.ptMinPosition.y = 0;
wndPlacement.rcNormalPosition.bottom = g_nWindowHeight;
wndPlacement.rcNormalPosition.left = 0;
wndPlacement.rcNormalPosition.top = 0;
wndPlacement.rcNormalPosition.right = g_nWindowWidth;
Here's where I create the window
// First we must register the class
assert( RegisterClassEx( in_wndClassDescription ) != 0 );
RECT windowRect; // Grabs Rectangle Upper Left / Lower Right Values
windowRect.left=(long)0; // Set Left Value To 0
windowRect.right=(long)in_nWindowWidth; // Set Right Value To Requested Width
windowRect.top=(long)0; // Set Top Value To 0
windowRect.bottom=(long)in_nWindowHeight; // Set Bottom Value To Requested Height
// Get a pixel perfect window
AdjustWindowRectEx( &windowRect, in_unWindowStyle, FALSE, in_unWindowExStyle );
// Then we must create the window from the data provided;
out_handleWindow = CreateWindowEx( in_unWindowExStyle,
in_wndClassDescription->lpszClassName,
in_szProgramName,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | in_unWindowStyle,
0,
0,
in_nWindowWidth,
in_nWindowHeight,
NULL,
NULL,
in_handleCurrentInstance,
NULL );
assert( out_handleWindow != NULL );
// Show the window and start updating it
ShowWindow( out_handleWindow, SW_SHOW );
UpdateWindow( out_handleWindow );
Here's where I init the device
//////////////////////////////////////////////////////////////////////////
// Platform Specific Initialization (Windows)
#if USING_WINDOWS
// Store the HWND
m_handleWindowHandle = programWindow->GetWindowHandle();
// Do a NULL check if we are in Debug
ASSERT_NULL( m_handleWindowHandle );
// Get the Device Context
m_handleDeviceContext = GetDC( m_handleWindowHandle );
// Null check the DC
ASSERT_NULL( m_handleDeviceContext );
//////////////////////////////////////////////////////////////////////////
// Set the pixel format
m_tPixelFormat.nSize = sizeof( PIXELFORMATDESCRIPTOR ); // Size of the PFD
m_tPixelFormat.nVersion = 1; // Set the version number
m_tPixelFormat.dwFlags = ( PFD_DRAW_TO_WINDOW | // Set the formats
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER );
m_tPixelFormat.iPixelType = PFD_TYPE_RGBA; // Set the color format
m_tPixelFormat.cColorBits = 32; // Set the color depth
m_tPixelFormat.cDepthBits = 32; // Set the depth buffer depth
m_tPixelFormat.cStencilBits = 0; // Set the stencil buffer depth
m_tPixelFormat.iLayerType = PFD_MAIN_PLANE; // Set the layer for the app
// See if there is a pixel format that will match our requests
int nPixelFormat = 0;
ASSERT_FALSE( nPixelFormat = ChoosePixelFormat( m_handleDeviceContext,
&m_tPixelFormat ) );
ASSERT_FALSE( SetPixelFormat( m_handleDeviceContext,
nPixelFormat,
&m_tPixelFormat ) );
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// So far so good... Now we try to create our RenderContext (HRC)
HGLRC tempContext = wglCreateContext( m_handleDeviceContext );
ASSERT_NULL( tempContext );
// See if the tempContext will work
ASSERT_FALSE( wglMakeCurrent( m_handleDeviceContext, tempContext ) );
GLenum error = glewInit();
if( error != GLEW_OK )
{
fprintf(stderr, "Error: %s\n", glewGetErrorString(error));
}
if( wglewIsSupported( "WGL_ARB_create_context" ) == 1 )
{
// Define our attributes for using OpenGL 3.0 and forward
int attribs[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,//we want a 3.0 context
WGL_CONTEXT_MINOR_VERSION_ARB, 0,
//and it shall be forward compatible so that we can only use up to date functionality
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
0}; //zero indicates the end of the array
m_handleGLRenderContext = wglCreateContextAttribsARB( m_handleDeviceContext, 0, attribs );
ASSERT_NULL( m_handleGLRenderContext );
ASSERT_FALSE( wglMakeCurrent( NULL, NULL ) );
ASSERT_FALSE( wglDeleteContext( tempContext ) );
ASSERT_FALSE( wglMakeCurrent( m_handleDeviceContext, m_handleGLRenderContext ) );
}
else
{
m_handleGLRenderContext = tempContext;
}
//////////////////////////////////////////////////////////////////////////
#endif
Resize( programWindow->GetWindowWidth(), programWindow->GetWindowHeight() )
Here's where I init the renderer
glEnable(GL_DEPTH_TEST); // Enable depth testing
glDepthFunc( GL_LEQUAL ); // Reject anything less than or equal to the current depth
glClearDepth( 1.0f ); // We clear to full depth
glClearStencil( 0 ); // We clear the stencil buffer to false
glCullFace(GL_FRONT); // Enable culling
glClearColor(0.5f, 0.5f, 1.0f, 1.0f); // The color to clear the background to
And lastly here's my WndProc
switch( unMessage )
{
case WM_SIZE:
// Resize the window
CDeviceManager::GetInstance()->Resize( LOWORD( lParam ),
HIWORD( lParam ) );
break;
case WM_PAINT:
if( CGame::GetInstance()->IsGameActive() )
{
CGame::GetInstance()->Render();
}
break;
case WM_CLOSE:
// Free up resources if the red x is pressed
CGame::GetInstance()->Destroy();
CDeviceManager::GetInstance()->Destroy();
g_cWindow.Destroy();
break;
default:
return DefWindowProc( handleWindow,
unMessage,
wParam,
lParam );
Please guys, I'm at my wits end on this.
Also if I press close, when it registers about minute later, I do see the clear color for just a second :/