Shaders and JOGL

I’m implementing shaders with glsl in my JOGL applet. Everything works fine, except textures. If I try to access to texture 1 (With MultiTexture activated) , my program access to texture 0. I pass the unit of texture as a uniform to texture2D function. There is no way to say to my fragment shader which texture I need to view.

The fragment shader is very simple:

uniform sampler2D colorMap;
uniform sampler2D envMap;
void main()
{
vec4 color = texture2D(colorMap,gl_TexCoord[0].st);
vec4 env = texture2D(envMap,gl_TexCoord[1].st);
gl_FragColor=color+env*0.4;
}

It gets colorMap=0, envMap=0 . I believe this, because it applies as colorMap texture0 and as envMap texture0

I answer myself. Before calling glUniform you must call glActiveProgram

Could you give me an example of shader to handle Phong model with textures please?

It shouldn’t be that hard to find a Phong implementation on the web and just add some texturing support. I would think all you need to do is calculate the phong lighting from before and then modulate it with the textures.

gouessej, I haven’t one. But there are many samples in the web. In any case, it is not hard to implement one.

Take a look at these tuts

http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2

http://www.ozone3d.net/tutorials/glsl_lighting_phong.php

Thanks but the main difficulty is to adapt it to handle the textures.

So, the lambertian term should be between 0 and 1. Multiply that value by the R, G, B sample you get from the texture. Then add the ambient to it. Then add the specular to it. Really, not difficult.

Ok thank you very much. I’m a newbie in GLSL, sorry.