Archived

This topic is now archived and is closed to further replies.

wglMakeCurrent problems...

This topic is 5142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How is wglMakeCurrent working? My rendering loop always looked like: if (wglGetCurrentContext()==NULL) wglMakeCurrent(hDC,hRC); render(); SwapBuffers(hDC); And that works fine. However if I do like: wglMakeCurrent(hDC,hRC); render(); SwapBuffers(hDC); It does just display a grey background (which is refreshed). Why? Recently I implemented offscreen rendering using p buffers. My loop looks like this: wglMakeCurrent(pBuffer_hDC,pBuffer_hRC); renderToBuffer(); wglMakeCurrent(normal_hDC,normal_hRC); render(); SwapBuffers(hDC); and this does not work either!! It displays one frame and then keeps displaying the same frame (no change). Please tell me what I am doing wrong. Thanks

Share this post


Link to post
Share on other sites
Probably when you call MakeCurrent in the first code you use the right hDC,hRC...in the other codes you use different (and wrong) hDCs. hdc must be the same also in SwapBuffer()...
My suggestion is to create an hdc and consequently an hrc in your init routine for every context (window, bitmap or pbuffer) and then use something like this

if(GetCurrentContext()!=hrc)
{
MakeCurrent(hdc,hrc);
}
//
// Render
//
SwapBuffer(hdc);


However it is said to say that in Windows and OpenGL hdcs are strange things....

Share this post


Link to post
Share on other sites
Thanks blizzard999,

I found the problem and apologize for my stupidity:
When I created the context with

hRC=wglCreateContext(hDC);

hRC was a local variable masking the global one! Later I used the global version of hRC which explains why it didn''t work!

I have another quick question:

glGetError is supposed to return the last error code and clear the last error. In my code, I activate my pbuffer with:

int e0=glGetError();
bool successful=wglMakeCurrent(pBuffer_hDC,pBuffer_hRC);
int e1=glGetError();
int e2=glGetError();

The strange thing is:

e0=GL_NO_ERROR
successful=true
e1=GL_INVALID_OPERATION
e2=GL_INVALID_OPERATION

1.) How can my call be successful and generate an error code at the same time?
2.) Why is e2 not GL_NO_ERROR? (the error code should be cleared after the call int e1=glGetError(); )

Share this post


Link to post
Share on other sites