Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: glut subwindow prevents shader from working

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    3

    glut subwindow prevents shader from working

    I have a glut/opengl 1.4 program that uses the fixed function pipeline
    and a shader . Since I wanted to add some new feature to this program
    I decided to transfer it to some more modern version of opengl, I tried 3.0 .
    Result: If the main window has a glut subwindow glUseProgram does not
    work, Errorcode: 1281 , although the shaderprogram compiled and linked without
    errors.
    If no subwindow is created the shader works as expected.
    In the opengl 1.4 version the shader works despite the subwindow.
    I tried this on AMD Graphics with fglrx and on Intel graphics with
    the open source driver.
    In the latter one the shader works in den subwindow, but not
    in den the main window if there is a subwindow.

    The subwindow contains the menues of the userinterface so I cannot
    do without it, so the only way seems to be programming opengl 1.4 ,
    or is there another way ?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,156
    Are you writing your code properly to account for the fact that each window/subwindow has its own GL context?

    You might post a short, standalone GLUT test program that illustrates your problem so folks can try it and give you suggestions.

    Here's a tutorial on using GLUT subwindows that might be useful to you:

    * Subwindows (Lighthouse3D)

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,477
    Note that FreeGLUT and OpenGLUT allow you to control whether to create a new context with
    Code :
    glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
    glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_CREATE_NEW_CONTEXT);
    The default is to create a new context for each window, and that's the only choice in the original GLUT. The other option results in each window using the context which was current at the time the window was created.

    GLUT doesn't provide the option to share data between contexts, so if you use multiple contexts, you have to create resources (programs, textures, buffers, etc) separately for each context.

  4. #4
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    3
    I found out that things work as expected when I compile and link the shader-program
    after doing glutSetWindow to the window I want to use the shader in.
    I cannot use one compiled and linked shader program in more than one window,
    then error 1281 comes.

    On the other hand I want different callback funktions for each subwindow, can I
    have this if I use glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,156
    Probably so. Give it a try.

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,477
    Quote Originally Posted by carla_sch View Post
    On the other hand I want different callback funktions for each subwindow, can I
    have this if I use glutSetOption(GLUT_RENDERING_CONTEXT, GLUT_USE_CURRENT_CONTEXT);
    Yes (provided that you're using FreeGLUT or OpenGLUT, not the original GLUT).

    But then, all state is shared between windows. So you need to set everything in the display callback. That includes the viewport and projection matrix (it's quite common for those to be set in the resize callback, but that won't work if you're using a single context for all windows).

    State which is supposed to be common to all windows can be set in callbacks, but anything which is supposed to be per-window has to be stored in a variable, with the GL state set from the variable within the display callback.

Posting Permissions

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