wglMakeCurrent: problem with ati graphic card

Hello everyone!

I’m an intern and my task is to find a bug in an opengl program, which saves a screenshot of an opengl object in a .bmp format.

On a computer with a nvidia graphic card it is no problem, but on a laptop with an ati graphic card, there is a little problem.

Whenever it calls the wglMakeCurrent(m_hdc, m_hGLrc); function, it gives me an exception.

“0xC0000005:Zugriffsverletzung beim Lesen an Position x00000120” Translation: :slight_smile:
“00xC0000005:Access Violation while reading position 0x00000120”

(The graphic card is an ati mobility radeon x300)

But as mentioned on the nvidia computer everything works. :frowning:

Does anyone know this problem, or even has a solution for it?

I am thankful for any kind of help.

Probably it’s a driver bug. Can you send us some source code listing?

view->get_viewport( x, y, width, height );

int WindowWidth = 4096;
int WindowHeight = 4096;

int MaxTextureSize = 0;
int MaxFrameSize = 0;

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &MaxTextureSize);
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &MaxFrameSize);

if ( MaxTextureSize < WindowWidth ) WindowWidth = MaxTextureSize;
if ( MaxTextureSize < WindowHeight ) WindowHeight = MaxTextureSize;

if ( MaxFrameSize < WindowWidth ) WindowWidth = MaxFrameSize;
if ( MaxFrameSize < WindowHeight ) WindowHeight = MaxFrameSize;

// allocate final image buffer
GLubyte* image = reinterpret_cast<GLubyte*>( malloc( WindowWidth * WindowHeight * 3 ) );
GLubyte* cimage = reinterpret_cast<GLubyte*>( malloc( WindowWidth * WindowHeight * 3 ) );

clGLFrameBuffer* FrameBuffer = new clGLFrameBuffer( WindowWidth, WindowHeight, 8, true );

void clGLFrameBuffer::AfterConstruction()
glGenFramebuffersEXT( 1, &FFrameBuffer );

void clGLFrameBuffer::BindRenderTarget(int TargetIndex) const
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FFrameBuffer);
After this call my program calls this “make_current”-function and delivers me my “00xC0000005:Access Violation while reading position 0x00000120”-error.
void gl_context_data::make_current( view3d *view )
if (view)
wglMakeCurrent(m_hdc, m_hGLrc);
wglMakeCurrent(NULL, NULL);

I hope that this little extract can illustrate the problem a little bit.

OK. I’m interested in the code which gets the DC of the window and creates the RC.

Ok. I hope this is the right thing

if( m_hdc == NULL)
m_hdc = CreateCompatibleDC( NULL);
if( m_hdc == NULL)

if (m_hGLrc)
m_hGLrc = wglCreateContext(m_hdc);
#ifdef _DEBUG

Seems that you use a NULL as the parameter to CreateCompatibleDC. You know that it won’t create a DC for your window, but rather it will create a memory device context?

Are you sure that you want to do here?

If think the created rendering context then maybe can be invalid, that’s why the exception. Btw it’s still a driver bug that it not gracefully returns an error code instead of crashing, but I suppose there is some problem also in your code.

Ok, first of all: Thanks for your help!

So if that is the problem, how can I create a DC for my window, rather than a memory device context?

I have tried to understand it, but I don’t get it :slight_smile:

Use the WinAPI function GetDC which has as parameter the handle for the window. For an on-screen context (actually for the context of the window), this should be used. After that request a rendering context in the same way as before just use the device context got from GetDC.

For a thorough and much more advanced context creation tutorial, check this:


Ok. I am now pretty sure, that there is a problem with the drivers. They don’t seem to support fbo.

My question is now, is there a possibility to solve this problem, without installing new drivers? Because the problem is, you can’t tell the customers, that they have to install new drivers. Has somebody an idea of a solution? Thx

There is no other possibility. If a driver does not support FBO then you cannot use it.

Usually softwares have in their documentation that latest drivers are required to run the software.

On the other hand you can create some limited fallback of FBOs using pbuffers but I don’t advice that, since that functionality is quite deprecated and limited.