Hi all,
I know how to use multitextures in glsl. However I couldn’t manage to write JOGL code to load multitextures to texture units. I only need the java code that sends textures to shaders. Here is what I do:
...
int vertexShader = loadShader(gl, GL.GL_VERTEX_SHADER, shader + ".vert");
int fragmentShader = loadShader(gl, GL.GL_FRAGMENT_SHADER, shader + ".frag");
program = createProgram(gl, vertexShader, fragmentShader);
colorMap = gl.glGetUniformLocation(program, "colorMap");
normalMap = gl.glGetUniformLocation(program, "normalMap");
try
{
Texture texture;
gl.glActiveTexture(GL.GL_TEXTURE0);
texture = TextureIO.newTexture(getFile("color_map.jpg"), false);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureObject());
gl.glActiveTexture(GL.GL_TEXTURE1);
texture = TextureIO.newTexture(getFile("normal_map.jpg"), false);
gl.glBindTexture(GL.GL_TEXTURE_2D, texture.getTextureObject());
}
catch(Exception e)
{
e.printStackTrace();
}
...
gl.glUseProgram(program);
gl.glUniform1i(colorMap, 0);
gl.glUniform1i(normalMap, 1);
gl.glBegin(GL.GL_QUADS);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0, 0);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0, 0);
gl.glVertex2f(0, 0);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 1, 0);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 1, 0);
gl.glVertex2f(1, 0);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 1, 1);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 1, 1);
gl.glVertex2f(1, 1);
gl.glMultiTexCoord2f(GL.GL_TEXTURE0, 0, 1);
gl.glMultiTexCoord2f(GL.GL_TEXTURE1, 0, 1);
gl.glVertex2f(0, 1);
gl.glEnd();
vertex shader
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = ftransform();
}
fragement shader
uniform sampler2D colorMap;
uniform sampler2D normalMap;
void main()
{
vec3 normal = normalize(texture2D(normalMap, gl_TexCoord[1].st).xyz);
vec3 lightVector = vec3(0, 0, 1);
float intensity = max(dot(normal, lightVector), 0);
gl_FragColor = intensity * texture2D(colorMap, gl_TexCoord[0].st);
}
any help?
thanks in advance,
Ozgur