pthread and opengl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leon

    pthread and opengl

    Hey, i am trying to develop a game, and I am using OpenGL and pthread.
    (on Ubuntu, so i also use the X library.) Now i have a problem. I have
    initialized OpenGL in the main thread, and i want to repaint 30 times
    every second (the usual framerate). Now i programmed a timer, which was
    able to wait for 30/1000 seconds. That happens in another thread, and
    after the delay (nanosleep, from the time.h header), it calls the paint()
    function. And it returned a error message. I found out that it was
    because OpenGL can't be painted from a different thread than the
    initialising thread. Can anyone help me what to do to fix this? I can't
    let the initialising thread delay and repaint, because it has to wait for
    X inputs.

    (main_thread)
    |
    \ /

    (initialize OpenGL)
    |
    \ /

    (start painting timer)
    | \
    \ / \
    (wait for X events, XNextEvent()) |
    \ /
    (wait 30/1000 second, and then
    call the repaint function)


    Can anyone help me please?

    grz, Leon
  • dave_mikesell@fastmail.fm

    #2
    Re: pthread and opengl

    On Feb 10, 10:37 am, Leon
    <ask.me.if.you. want.my.email.a ddr...@this.lis twrote:
    Hey, i am trying to develop a game, and I am using OpenGL and pthread.
    You're better off asking in comp.graphics.a pi.opengl - this group only
    deals with standard C++.

    Keep in mind, though, that OpenGL is a big state machine and it's not
    thread safe, so you have to manage thread access to the OpenGL
    context.

    Comment

    • Leon

      #3
      Re: pthread and opengl

      On Sun, 10 Feb 2008 07:46:12 -0800, dave_mikesell wrote:
      On Feb 10, 10:37 am, Leon
      <ask.me.if.you. want.my.email.a ddr...@this.lis twrote:
      >Hey, i am trying to develop a game, and I am using OpenGL and pthread.
      >
      You're better off asking in comp.graphics.a pi.opengl - this group only
      deals with standard C++.
      >
      Keep in mind, though, that OpenGL is a big state machine and it's not
      thread safe, so you have to manage thread access to the OpenGL context.
      Okay, thank you

      Comment

      • Rolf Magnus

        #4
        Re: pthread and opengl

        Leon wrote:
        Hey, i am trying to develop a game, and I am using OpenGL and pthread.
        Both OpenGL and pthreads are off-topic here. A better newsgroup for your
        question is comp.graphics.a pi.opengl.
        I found out that it was because OpenGL can't be painted from a different
        thread than the initialising thread. Can anyone help me what to do to fix
        this?
        Most OpenGL implementations aren't thread-safe. You must do all the OpenGL
        calls in one thread.

        Comment

        Working...