Problem with glClear

Started by
7 comments, last by V-man 13 years ago
Hey guys,

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?

Perception is when one imagination clashes with another
Advertisement
Other information:

I'm only calling glClear and the SwapBuffers every frame. It doesn't matter which bits I clear.

My resolution is 1280 by 720.

I set my clear color to be a non-black color.

Perception is when one imagination clashes with another
You've obviously got a bad context. Could you add some error checking to your 3.0 context creation and see what that gives you back? Also maybe ZeroMemory your m_tPixelFormatbefore doing any creation and make sure that you're not calling ReleaseDC on m_handleDeviceContext while your context exists. CS_OWNDC on your WNDCLASS(EX) shouldn't really be necessary any more, but I prefer to do it anyway just in case drivers expect it to be there (I've found one or two particularly poor ones that semi-explode without it).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I am using ZeroMemory on the m_tPixelFormat.

At the time of initialization the HDC = 0x85012263 and the HGLRC = 0x00010001

When I call present the values are the same.

I haven't hit any ReleaseDC calls, accidentally or otherwise.

I'm using CS_OWNDC on my windows for backwards compatibility.

glewInit() returns GLEW_OK

wglMakeCurrent returns fine.

SwapBuffers returns fine.

Perception is when one imagination clashes with another
As of now, I can debug and step through all the functions fine with no errors being thrown. In fact, I can debug with no slow down either. But if I just let the program run the screen A.) doesn't clear to the color I specified and B.) doesn't respond to window messages very fast (like ten to fourty five seconds slow). This only happens if I call glClear. Someone must have ran into this before.
Perception is when one imagination clashes with another
Are you calling your render function from WM_PAINT?

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

I wasn't at the time, but I am now, with now change :/

Perception is when one imagination clashes with another
*no change
Perception is when one imagination clashes with another
http://www.opengl.org/wiki/FAQ#How_do_I_tell_what_version_of_OpenGL_I.27m_using.3F
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement