Light shader and texture (in display lists...)


I had an old code like this :

I replaced it with :
SendColor with glUniform

But in some display lists there are textures. And in these cases my shader does not render the texture…
I have seen today that in classical code the textures are sent to the shader.

I can not change the display lists code (lot of old existing code…).

1- What can I do to obtain the correct rendering (I am a beginner…) ?
2- Is there a solution with minor change in the display lists ?

Thanks for your advices.

[QUOTE=AllForum;1246006]1- What can I do to obtain the correct rendering (I am a beginner…) ?
2- Is there a solution with minor change in the display lists ?[/QUOTE]
It depends what all is in the display list and what exactly you’re trying to do.

The display lists draw geometry with old opengl 1.1 functions :

  • they set geometry attributes : line width, line stipple, polygon stipple or texture
  • they draw the geometry with basic functions and glutess
    they draw text : i do not understand the code but it seems to be only geometry (wglUseFontOutlines, gl_quads and glutess).

The shader I added is a simple phong shader to add light.
And I suppressed the glcolor because I learned here that it’s wrong to use old opengl 1.1 functions. :wink:
But I did not thought to the textures… I did not read things about textures when I read how a shader works…

And I use opengl 2.0 or 2.1…


I am trying something but it does not work yet. I would like to know if it may work :

  • I create a display list and store the textureID used during the display list creation.

When I render :

  • Send textureID with glUniform to the fragment shader
  • glCallList(l);

In the fragment shader I retrieve the texel :

  • vec4 texel = texture2D(TextureID, gl_TexCoord[0].st);

Does this work ?
If yes I will search why the texture is black…


The answer is: NO.
The first parameter of texture2D is not a texture ID. Setting texture inside DL is generaly a bad idea.

Let me explain the previous answer a little bit better…
The first parameter of the texture2D is a sampler. A sampler defines which texture unit will be used for the texture lookup.
To associate a texture to a texture unit you should use glActiveTexture(…);/glBindTexture(…); pair. The value in the sampler should be the value set in glActiveTexture(value) (or to bi more precise, value-GL_TEXTURE0). As you can see, glBindTexture(…) should be call explicitly in GL code.

Considering DLs, binding textures should be done outside of them. There are different problems if you do in in a compiled DL. From very slow execution to different anomalies. Try to pull them out of DLs to see if there are any improvements.

Thanks for your help.
I did stupid things with texture id in place of sampler.
Now without changing my code but with the pair glActiveTexture(…);/glBindTexture(…); I can see my texture.

[Edit] No more strange opengl errors. I sent invalid values with glUniform.[/Edit]

Is your advice concerning binding textures in DLs general or only when using shaders ? (we never had problem with our basic opengl 1.1 code).

Thanks for your help : I did not know what was wrong and I did not know what to try. I have things to test now.
[Edit2] All works ; I tested with tranparency too. [/Edit2]

Thanks !