Jump to content
  • Advertisement
Sign in to follow this  
ghgmc

OpenGL Multithread problem in OpenGL

This topic is 3474 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, I have a problem with OpenGL drawing in seperate threads to seperate windows interfering with each other. I have a Windows application with a large number of windows, but only two OpenGL windows. Each window was created in the main thread with CS_OWNDC and WS_CLIPCHILDREN and WS_CLIPSIBLINGS. One of the windows is larger than the other. Two seperate threads are then created. I get the handle for one of the windows in each thread, create a rendering context within the thread and call wglMakeCurrent in the thread. I then do double buffered drawing into the windows simultaneously. Initially, I was only using the larger window and everything works perfectly. There is also lots of stuff correctly happening in non-OpenGL windows drawn by other threads. However, as soon as I issue any OpenGL drawing command in the second thread (with the smaller window) it screws up the larger window. The drawing continues, but is now clipped to the top left corner of the large window in an area exactly the same size as the smaller window from the other thread. It also appears that a glClear in one thread clears the buffer in both. The swapbuffers in the larger window swaps the contents of the whole window - not just the clipped area - so that I see flickering between the last two correctly drawn full frames outside of the clipped area. It seems to make no difference what drawing commands are issued in the second thread - the large window is instantly clipped. The drawing in the smaller window is more or less correct - though the first thing drawn (a background rectangle) is not always correctly positioned or there at all. I've checked with Spy++ that both windows really do have CS_OWNDC set - and the handles and device contexts are definitely different. Any ideas? Thanks a lot, Gareth

Share this post


Link to post
Share on other sites
Advertisement
Last time I done this, I created each window in a separate thread, then created the context.

Share this post


Link to post
Share on other sites
Thanks both of you.

I just found the problem - the HandleExpose for the window was calling some OpenGL code directly from the parent thread instead of passing a message to do the refresh in the proper thread. I don't know why this should cause it to draw to the other wrong "child" thread - but it did.

It works now anyway.

Thanks a lot,

Gareth

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!