GLSL examples do not work

Hello all,

I am a new developer to all: GLSL, HLSL, NVIDIA and else.

I am trying to learn now this library and trying to port it in a opengl app.

So I of course want to first make any of 2 opengl examples to work, however both are not:

1- Distilling_GLSL gives the following error :

OpenGL error 0x0506 in file /home/sariug/mdl-sdk-317500.2554/examples/mdl_sdk/distilling_glsl/example_distilling_glsl.cpp, line 1085.

2- Execution_GLSL gives the following error:

Error compiling the fragment shader: 0:78(46): warning: `tex_start' used uninitialized
0:78(17): error: sampler arrays indexed with non-constant expressions are forbidden in GLSL 1.30 and later
0:86(49): warning: `tex_start' used uninitialized
0:86(20): error: sampler arrays indexed with non-constant expressions are forbidden in GLSL 1.30 and later

What would your suggestions be to fix them ?

Best regards,


can you give some details on your system? (OS, hardware, driver, OpenGL/GLSL version)

The first idea is that you seem to run a pretty old OpenGL/GLSL version.

Best Regards

VERSION=“18.04.3 LTS (Bionic Beaver)”

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel® Haswell Mobile
OpenGL core profile version string: 4.5 (Core Profile) Mesa 19.0.8
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 19.0.8
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 19.0.8
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

Anything is missing ?

Yes, this is helpfull. The distilling example by default uses a few OpenGL extensions. You can increase the compatibility by:
in example_distilling_glsl.cpp
comment line 38 out (i.e. do not define USE_SSBO
uncomment line 50 (#define REMAP_NOISE_FUNCTIONS)

If this does not help we will nood to take a closer look.

you might also try forcing the OpenGL version by setting the environment variable


The error stays unfortunately.

OpenGL error 0x0506 in file /home/sariug/Library_Archive/nvidia_mdl/mdl-sdk-317500.2554/examples/mdl_sdk/distilling_glsl/example_distilling_glsl.cpp, line 1085.

Is there maybe any other idea ?

Best regards,

The function is setting up a floating point texture. Googling a bit it seems only the windows driver for intel integrated might support floating point textures.

[i]If you have not already done so:

Install the latest drivers from oibaf/ppa

sudo apt-add-repository ppa:oibaf/graphics-drivers
sudo apt-get update
sudo apt-get dist-upgrade

to check for the floating-point textures:

glxinfo | grep -i texture_float

If you get some output, you may assume that it is present.[/i]

do you get output?

Thats what I was afraid of. If my drivers are not capable of

The output I have gotten is :

GL_ARB_texture_filter_anisotropic, GL_ARB_texture_float, 
    GL_ATI_texture_float, GL_EXT_EGL_sync, GL_EXT_abgr, 
    GL_ARB_texture_float, GL_ARB_texture_gather, 
    GL_ATI_texture_float, GL_EXT_EGL_sync, GL_EXT_abgr, GL_EXT_bgra, 
    GL_OES_texture_cube_map_array, GL_OES_texture_float, 
    GL_OES_texture_float_linear, GL_OES_texture_half_float,

Is not this a proper output ? what do you think ?

The output looks good.
And after the driver update you still get the same error?

Yes exactly…

Hi sariug,

for the problem with execution_glsl, please try replacing tex_lookup_2d() and tex_texel_2d() in example_execution_glsl.frag by these functions:

// Implementation of tex::lookup_*() for a texture_2d texture.
vec4 tex_lookup_2d(uint tex, vec2 coord, int wrap_u, int wrap_v, vec2 crop_u, vec2 crop_v)
    if (tex == 0u) return vec4(0);
    switch (tex_start + tex - 1u)
        case  0: return texture(material_texture_samplers_2d[ 0u], coord);
        case  1: return texture(material_texture_samplers_2d[ 1u], coord);
        case  2: return texture(material_texture_samplers_2d[ 2u], coord);
        case  3: return texture(material_texture_samplers_2d[ 3u], coord);
        case  4: return texture(material_texture_samplers_2d[ 4u], coord);
        case  5: return texture(material_texture_samplers_2d[ 5u], coord);
        case  6: return texture(material_texture_samplers_2d[ 6u], coord);
        case  7: return texture(material_texture_samplers_2d[ 7u], coord);
        case  8: return texture(material_texture_samplers_2d[ 8u], coord);
        case  9: return texture(material_texture_samplers_2d[ 9u], coord);
        case 10: return texture(material_texture_samplers_2d[10u], coord);
        case 11: return texture(material_texture_samplers_2d[11u], coord);
        case 12: return texture(material_texture_samplers_2d[12u], coord);
        case 13: return texture(material_texture_samplers_2d[13u], coord);
        case 14: return texture(material_texture_samplers_2d[14u], coord);
        case 15: return texture(material_texture_samplers_2d[15u], coord);
        case 16: return texture(material_texture_samplers_2d[16u], coord);
        case 17: return texture(material_texture_samplers_2d[17u], coord);
        case 18: return texture(material_texture_samplers_2d[18u], coord);
        case 19: return texture(material_texture_samplers_2d[19u], coord);
        case 20: return texture(material_texture_samplers_2d[20u], coord);
        case 21: return texture(material_texture_samplers_2d[21u], coord);
        case 22: return texture(material_texture_samplers_2d[22u], coord);
        case 23: return texture(material_texture_samplers_2d[23u], coord);
        case 24: return texture(material_texture_samplers_2d[24u], coord);
        case 25: return texture(material_texture_samplers_2d[25u], coord);
        case 26: return texture(material_texture_samplers_2d[26u], coord);
        case 27: return texture(material_texture_samplers_2d[27u], coord);
        case 28: return texture(material_texture_samplers_2d[28u], coord);
        case 29: return texture(material_texture_samplers_2d[29u], coord);
        case 30: return texture(material_texture_samplers_2d[30u], coord);
        case 31: return texture(material_texture_samplers_2d[31u], coord);
        default: return vec4(0);

// Implementation of tex::texel_*() for a texture_2d texture.
vec4 tex_texel_2d(uint tex, ivec2 coord, ivec2 uv_tile)
    if (tex == 0u) return vec4(0);
    switch (tex_start + tex - 1u)
        case  0: return texelFetch(material_texture_samplers_2d[ 0u], coord, 0);
        case  1: return texelFetch(material_texture_samplers_2d[ 1u], coord, 0);
        case  2: return texelFetch(material_texture_samplers_2d[ 2u], coord, 0);
        case  3: return texelFetch(material_texture_samplers_2d[ 3u], coord, 0);
        case  4: return texelFetch(material_texture_samplers_2d[ 4u], coord, 0);
        case  5: return texelFetch(material_texture_samplers_2d[ 5u], coord, 0);
        case  6: return texelFetch(material_texture_samplers_2d[ 6u], coord, 0);
        case  7: return texelFetch(material_texture_samplers_2d[ 7u], coord, 0);
        case  8: return texelFetch(material_texture_samplers_2d[ 8u], coord, 0);
        case  9: return texelFetch(material_texture_samplers_2d[ 9u], coord, 0);
        case 10: return texelFetch(material_texture_samplers_2d[10u], coord, 0);
        case 11: return texelFetch(material_texture_samplers_2d[11u], coord, 0);
        case 12: return texelFetch(material_texture_samplers_2d[12u], coord, 0);
        case 13: return texelFetch(material_texture_samplers_2d[13u], coord, 0);
        case 14: return texelFetch(material_texture_samplers_2d[14u], coord, 0);
        case 15: return texelFetch(material_texture_samplers_2d[15u], coord, 0);
        case 16: return texelFetch(material_texture_samplers_2d[16u], coord, 0);
        case 17: return texelFetch(material_texture_samplers_2d[17u], coord, 0);
        case 18: return texelFetch(material_texture_samplers_2d[18u], coord, 0);
        case 19: return texelFetch(material_texture_samplers_2d[19u], coord, 0);
        case 20: return texelFetch(material_texture_samplers_2d[20u], coord, 0);
        case 21: return texelFetch(material_texture_samplers_2d[21u], coord, 0);
        case 22: return texelFetch(material_texture_samplers_2d[22u], coord, 0);
        case 23: return texelFetch(material_texture_samplers_2d[23u], coord, 0);
        case 24: return texelFetch(material_texture_samplers_2d[24u], coord, 0);
        case 25: return texelFetch(material_texture_samplers_2d[25u], coord, 0);
        case 26: return texelFetch(material_texture_samplers_2d[26u], coord, 0);
        case 27: return texelFetch(material_texture_samplers_2d[27u], coord, 0);
        case 28: return texelFetch(material_texture_samplers_2d[28u], coord, 0);
        case 29: return texelFetch(material_texture_samplers_2d[29u], coord, 0);
        case 30: return texelFetch(material_texture_samplers_2d[30u], coord, 0);
        case 31: return texelFetch(material_texture_samplers_2d[31u], coord, 0);
        default: return vec4(0);

And limiting MAX_TEXTURES in example_execution_glsl.cpp to 32 instead of 64.
This will ensure, that the array indices are constant at every texture function call and will additionally improve compatibility with very old graphic cards.

About the distilling_glsl example: Can you tell me, from where create_gl_texture() is called, when it fails, and what the values of target, w, h, format and levels are?

Best regards