Sign in to follow this  

OpenGL OpenGL and Context Switching Question

Recommended Posts

I have a question regarding context switch when writing an application in Windows. I have an application which spawns new pop-up windows containing different OpenGL scene renders. I used wglCreateContext to make two different OpenGL contexts. However, I created them at startup before creating new threads for the pop-ups. I know I should change it to create the context as I create new threads. However, it worked. At application startup, I create the multiple contexts and I set them with the correct OpenGL setups (viewports etc.). I go through a loop set all the contexts. However, this happens in the main startup thread. I'm still able to draw in the other pop-up window threads by forcing a wglMakeCurrent. Here is where I come into trouble. When I get a windows message from the main thread, I try the same trick and loop through all my context forcing the wglMakeCurrent. However, this is done through the main thread at the point the message comes in. I realize if I send a message to my other thread and have them do their individual contexts that it will probably work. I also know that each thread must have its own context. When does the context get tied to a thread? Why did my placing contexts into an array and doing OpenGL settings from the main thread work part of the time. This post is more for informational purposes on my part. I know how to fix it. I would like more understanding of the situation. Thanks.

Share this post

Link to post
Share on other sites

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