Sign in to follow this  

wglDeleteContext, wglMakeCurrent and resources

This topic is 4309 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

Hi! My question is similar to: http://www.gamedev.net/community/forums/topic.asp?topic_id=307699 but that is unanswered and even I wasn't able to post a reply (which was going to be further questions anyways). So: is there a way to free context-associated resources when a HDC is not available for the appropriate RC? I mean there would be a drawing function which gets a HDC in parameter, sets wglMakeCurrent (hDC, hRC), performs some drawing, then releases the DC with wglMakeCurrent (NULL, NULL). I certainly won't want to delete all the display lists at this point, otherwise I would have to recompile them the next update time. (I have to release the DC in order to draw on it using GDI later). This repeats several times then I want to clean up things. Do I have to present a valid HDC to the clean up code (in order to be able wglMakeCurrent the RC) or does wglDeleteContext automatically free up all the display lists (and other resources) bound to it? I tried wglMakeCurrent (NULL, hRC) and then glDeleteLists but that doesn't seem to work. Thx in advance!

Share this post


Link to post
Share on other sites
I believe the answer to the question in the linked thread is yes. All resources associated with a context are freed when it destroyed unless they are shared with another context. In that case they are freed when the last shared context is deleted.

In answer to your question, you do not need the dc in order to destroy the opengl context. Just make sure the context is not bound to another thread and call wglDeleteContext(yourContext). The context you are deleting does not need to be bound to the current thread in order to delete the context, though to use it for rendering or to delete specific resources individually it does need to be bound.

[quote]
I tried wglMakeCurrent (NULL, hRC) and then glDeleteLists but that doesn't seem to work.
[quote]

In order to bind the context to the thread with wglMakeCurrent, you need to provide a DC. This does not need to be the same DC you created the rendering context with, but it does need to be on the same device. One option is to use GetDC(myWindow) to get a hdc for the window you are rendering to. You should not need to delete the lists manually however if you are destroying the context.

Share this post


Link to post
Share on other sites

This topic is 4309 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this