Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Minimum calls for GL context creation

  1. #1
    Guest

    Minimum calls for GL context creation

    Hello everyone,

    I'm designing an API where two processes
    are running: one performs computations
    with GL (off screen rendering) and the other
    performs visualization.
    I can't modify the visualization process.
    I'd like to know what is the minimum code
    to set up a valid openGL context so that
    I can make my off screen computations
    (based on GL) ? I'm running under Windows2k,
    but if this code could be crossplatform...
    It's strange, I've been making gl code for
    several years, but as far as I was using
    GLUT I never had to ask myself about that...

    THanks for any suggestion,

    and a little subsidiary question.
    Provided that I'll have two valid openGL
    context at the same time (one for vis, the
    other for computing), this should be bad
    for perf, no ? I'd definitely better get
    the gl context of the visualization proc ?

    Many thanks again !

    GlOrbOfCoding()

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: Minimum calls for GL context creation

    For off-screen rendering, use a pbuffer. Specs are at the extensions registry and tutorials on how to set one up can be found at vendor sites(ATI,NVIDIA).

    EDIT: Remember that opengl is not thread-safe. It is suggested that if you have a multithreaded app, to do all gl interfacing in one thread. And don't even think about sharing a context between two processes.

    [This message has been edited by roffe (edited 10-02-2003).]

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Prague, Czech Rep., Europe
    Posts
    7

    Re: Minimum calls for GL context creation

    You'll have to do following steps to create rendering context under Win32:

    1. obtain device context of target window by calling GetDC()
    2. create the PIXELFORMATDESCRIPTOR structure and fill it in with appropriate content (see MSDN)
    3. call ChoosePixelFormat()
    4. call SetPixelFormat()
    5. create OpenGL rendering context by call wglCreateContext()
    6. attach OpenGL rendering context to device context by calling wglMakeCurrent()
    7. do Your own OpenGL operations
    8. detach OpenGL rendering context from device context by calling wglMakeCurrent()
    9. repeat steps 6-8 so many times You need
    10. destroy OpenGL rendering context by calling wglDeleteContext()

    It's recommended to execute steps 1-5 in response on WM_CREATE message, steps 6-9 in response on WM_PAINT message (or other messages from user interface), step 10 in response on WM_DESTROY message.

    This describes using OpenGL in Win32 environment, using in MFC is similar.

    But, You need render the OpenGL scene to the memory first, If I uderstand well. I recommend try to set dwFlags member of PIXELFORMATDESCRIPTOR to PFD_DRAW_TO_BITMAP value, create so called memory device context by calling CreateComapatibleDC(), create and select the appropriate bitmap to this context, and do all above descibed steps with that memory device context.


    Good Luck.

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: Minimum calls for GL context creation

    Above is for an on-screen buffer. He wanted for an off-screen buffer. This is very different.

  5. #5
    Guest

    Re: Minimum calls for GL context creation

    Thanks for all the suggestions...

    Roffe, all the coding for off-screen rendering is already written and fully works.
    My problem is that in my previous utilisation, I had my own visualization attached,
    and hence I had no problem of context.

    Now I'd like to set up a rendering context
    for off-line rendering, and possibly the
    minimum context. The fact is I do not fully
    understand the "why" of the different function
    ( choosePixelFormat, getDC, etc..) and as such
    I don't know which one are of use and which one are not...

    Thanks for your time,
    any explanation or hints welcomed !

    glOrbOfCoding()

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: Minimum calls for GL context creation

    Originally posted by glOrbOfCoding():
    Roffe, all the coding for off-screen rendering is already written and fully works.
    Rendering commands, whether they are to an on-screen or off-screen buffer are the same, that is trivial. This is not what I meant.


    My problem is that in my previous utilisation, I had my own visualization attached,and hence I had no problem of context.
    I have no idea what you are trying to say.


    I'd like to know what is the minimum code
    to set up a valid openGL context so that
    I can make my off screen computations
    (based on GL)?

    Now I'd like to set up a rendering context
    for off-line rendering, and possibly the
    minimum context.
    I'm confused. What do you want, an off-screen buffer(pbuffer) or an off-line buffer(bitmap/DIB)?

    And what do you mean by "and possibly the minimum context"? Every render buffer/target needs a rendering context.

    Basic code for off-screen(pbuffer) setup:
    -find correct pixelformat
    -create pbuffer
    -get pbuffer dc
    -create new rendering context or share with other dc
    -switch to that context with wglMakeCurrent

    For on-screen setup:
    -see above post

    for off-line(bitmap/dib) setup:
    -search microsoft's website


    [This message has been edited by roffe (edited 10-02-2003).]

  7. #7
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Prague, Czech Rep., Europe
    Posts
    7

    Re: Minimum calls for GL context creation

    Originally posted by roffe:
    Above is for an on-screen buffer. He wanted for an off-screen buffer. This is very different.
    roffe, read the last paragraph once more carefuly, there I described how to render into memory context, not on screen.

  8. #8
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: Minimum calls for GL context creation

    Ah, sorry, my bad.

    Personally I will never understand why people are interested in doing bitmap/dib/MS rendering, when there are so much better alternatives for sw rendering.

  9. #9
    Guest

    Re: Minimum calls for GL context creation

    Oups... It seems I was not clear at all
    in this thread.

    I have an algorithm that uses GPU to
    compute things that are NOT to be displayed
    (with render-to-tex and fragment prog).
    This is what I call off-screen rendering
    (sorry if I misused this word ? ).
    In my previous utilisation I was displaying part of the result (therefore I had a valid
    GL context). Now I want these computations
    to be stand alone.
    What I assume by "minimum context" is the
    niminum number of calls to set a valid rendering context (but that wont be used
    for online rendering). I already tried
    to make call for instance to:
    - glutInit
    - glutInitDisplayMode
    - glutCreateWindow,

    and then run the code. This solutions is
    ok, but I want to know if there is not
    a simpler way to define a context, with
    just a call to the functions I really need.

    Thks for your time guys !

    glOrbOfCoding()

  10. #10
    Member Regular Contributor
    Join Date
    Jun 2002
    Posts
    371

    Re: Minimum calls for GL context creation

    Originally posted by glOrbOfCoding():
    What I assume by "minimum context" is the
    niminum number of calls to set a valid rendering context (but that wont be used
    for online rendering). I already tried
    to make call for instance to:
    - glutInit
    - glutInitDisplayMode
    - glutCreateWindow,
    Well, glut is the easiest way to create an on-screen rendering context.

    But again, for rendering that isn't suppose to be displayed, use a pbuffer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •