I'm relatively new to OpenGL rendering so I've decided to start an OpenGL renderer.
This is my Initialization code:
//////////////////////////////////////////////////////////////////////////
// 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 = 16; // 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 );
wglMakeCurrent( NULL, NULL );
wglDeleteContext( tempContext );
wglMakeCurrent( m_handleDeviceContext, m_handleGLRenderContext );
}
else
{
m_handleGLRenderContext = tempContext;
}
//////////////////////////////////////////////////////////////////////////
#endif
Everything initializes fine and my HDC and HGLRC are fine. My problem is that when I call glClear( COLOR_BUFFER_BIT ) the program locks up and it takes ten to fifteen seconds to close the program when I hit the red x. If I comment out glClear it will run fine. Any ideas?