PDA

View Full Version : glut subwindow prevents shader from working



carla_sch
05-19-2017, 06:02 AM
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 ?

Dark Photon
05-19-2017, 06:31 AM
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 (http://www.lighthouse3d.com/tutorials/glut-tutorial/subwindows/) (Lighthouse3D)

GClements
05-20-2017, 05:19 AM
Note that FreeGLUT and OpenGLUT allow you to control whether to create a new context with


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.

carla_sch
05-20-2017, 09:25 AM
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);

Dark Photon
05-20-2017, 11:59 AM
Probably so. Give it a try.

GClements
05-20-2017, 03:04 PM
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.