Jump to content
  • Advertisement
Sign in to follow this  
fathom88

OpenGL OpenGL and Threads Question

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

I was trying to animate my OpenGL scene with a Windows App. I placed my draw routine inside the OnPaint routine. I created a separate thread which calls OnPaint every second. This does not work. Do I need to create a separate context because it's a separate thread? I know my draw routine works because I originally I had it tied to a button push. It would animate one frame at a time with each button press. Thanks for any help.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I think OpenGL isn't meant to work with multiple threads.... If you search the forums here @ Gamedev, you'll see that many people have problems like yours... So I think the simplest solution is to use only one thread for all that... From what I have seen before, the GL context cannot be shared... :(

Hope this helps...
Happy coding :)

Share this post


Link to post
Share on other sites
if you make your gl context current and the thread switches does some drawing
switches to another thread that calls makecurrent(0,0); and then jumps back to the drawing draw he would either draw to no context or to the wrong context

however you could synchronize this with a semaphore

a mutex is a semaphore with 0,1
a semaphore can is 0,n where n is a positiv number
if the semaphore is zero the thread blocks
and a semaphore my not become negative


P()
critical section do you rendering in here
V()


P requests a resource e.g. the device
V releases the device so the app can go on

if you have only one drawing context you could simply use a mutex
this all depends on how your system works you should definitely readup articles about threads generally you shouldn t spread one and the same job other several threads instead try moving more or less independly working systems into seperate threads to
a) avoid synchronization issues
b) reduce the number of mutex/semaphore locks
c) read up threading articles and do some sample implementations with e.g.: thread unsafe lists before you mess around with them in complex programm constructs you will save yourself a lot of debugging time trust me

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!