question about multitexturing with opengl shading language

Started by
8 comments, last by fazekaim 19 years, 8 months ago
I would like to use multitexturing with my indexed vertex arrays. The texturing is performed by a fragment program. The fragment program just draw the triangles with the second texture, and nothing more. (It's because this problem appeared) But I see the first one. What is the problem? Opengl code: gl.glEnableClientState( GL.GL_VERTEX_ARRAY ); gl.glEnableClientState( GL.GL_COLOR_ARRAY ); gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY ); gl.glVertexPointer( 3, GL.GL_FLOAT, 0, vertexBuffer[k][l] ); gl.glColorPointer( 4, GL.GL_UNSIGNED_BYTE, 0, colorBuffer[k][l]

); gl.glActiveTexture( GL.GL_TEXTURE0_ARB); gl.glClientActiveTextureARB( GL.GL_TEXTURE0_ARB); gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer ); gl.glBindTexture ( GL.GL_TEXTURE_2D, detailTextures[ p ] ); gl.glActiveTexture( GL.GL_TEXTURE1_ARB); gl.glClientActiveTextureARB( GL.GL_TEXTURE1_ARB); gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer ); gl.glBindTexture ( GL.GL_TEXTURE_2D, bumpMaps[k][l] ); gl.glUseProgramObjectARB( normalShaderObj ); int base = gl.glGetUniformLocationARB( normalShaderObj, "Base".getBytes() ); int bump = gl.glGetUniformLocationARB( normalShaderObj, "Bump".getBytes() ); int lightPos = gl.glGetUniformLocationARB( normalShaderObj, "lightPos".getBytes() ); gl.glUniform1iARB( base, 0 ); gl.glUniform1iARB( bump, 1 ); gl.glUniform3fARB( lightPos, 256.0f, 200.0f, 256.0f ); gl.glDrawElements( GL.GL_TRIANGLE_STRIP, vertexIndexCount, GL.GL_UNSIGNED_INT, vertexIndexBuffer[k][l] ); gl.glUseProgramObjectARB( 0 ); gl.glActiveTexture( GL.GL_TEXTURE0_ARB); gl.glDisable( GL.GL_TEXTURE_2D ); gl.glDisableClientState( GL.GL_VERTEX_ARRAY ); gl.glDisableClientState( GL.GL_COLOR_ARRAY ); gl.glDisableClientState( GL.GL_TEXTURE_COORD_ARRAY );

Advertisement
can you supply all your shader code as well plz....
Well, in the code you provided, you dont seem to be enabling GL_TEXTURE_2D anywhere, maybe this is the problem?

Remember, when you glActiveTexture(GL_TEXTURE0_ARB);you must also glEnable(GL_TEXTURE_2D); But that only enables texturing for GL_TEXTURE0_ARB, if you want to have 2 textures, you must do glActiveTexture(GL_TEXTURE1_ARB); and glEnable(GL_TEXTURE_2D); to enable textures for GL_TEXTURE1_ARB.
I put it to the code the
gl.glEnable( GL.GL_TEXTURE_2D ); statement, but my code still don't work.

My shader codes as You wished:

Vertex shader::::
varying vec4 color;
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
color = gl_Color;
}

Fragment shader:::
uniform sampler2D Base;
uniform sampler2D Bump;
varying vec4 color;
void main (void)
{
vec4 bumps = texture2D(Bump, gl_TexCoord[1].st );
gl_FragColor = bumps;
}
The shader render the first (GL_TEXTURE0_ARB) texture.
It is a problem through an oversight or a fatal mistake? :)

Thanks
I resolvedit:

gl.glClientActiveTextureARB( GL.GL_TEXTURE0_ARB);
gl.glBindTexture( GL.GL_TEXTURE_2D, groundDetailTextures[ p ] );
gl.glEnable( GL.GL_TEXTURE_2D);
gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer );
gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY );


gl.glClientActiveTextureARB( GL.GL_TEXTURE1_ARB);
gl.glBindTexture( GL.GL_TEXTURE_2D, groundBumpMaps[k][l] );
gl.glEnable( GL.GL_TEXTURE_2D);
gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer );
gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY );


"glClientActiveTextureARB(GLenum target) is the client state analog of glActiveTextureARB()" - reference :)

Thanks a lot anyway!
OOOOOOOOOOOOhhhhhhhhhhhhhhhhhhh!

The program render only the second texture :)))
So, my question is still active:))
Quote:Original post by fazekaim
I resolvedit:

gl.glClientActiveTextureARB( GL.GL_TEXTURE0_ARB);
gl.glBindTexture( GL.GL_TEXTURE_2D, groundDetailTextures[ p ] );
gl.glEnable( GL.GL_TEXTURE_2D);
gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer );
gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY );


gl.glClientActiveTextureARB( GL.GL_TEXTURE1_ARB);
gl.glBindTexture( GL.GL_TEXTURE_2D, groundBumpMaps[k][l] );
gl.glEnable( GL.GL_TEXTURE_2D);
gl.glTexCoordPointer( 2, GL.GL_FLOAT, 0, textureCoordinateBuffer );
gl.glEnableClientState( GL.GL_TEXTURE_COORD_ARRAY );


"glClientActiveTextureARB(GLenum target) is the client state analog of glActiveTextureARB()" - reference :)

Thanks a lot anyway!


the enabl;e texture + bind texture work on the current active texture unit.
with this code that texture unit is the same, (the client active texture unit changes though)
I think, I probed every combination with this code.
I have no idea.
I read every tutorial, and the code should be working.
I don't know...
The problem as, that the texture names in the fragment shader started with capital letter.
I renamed "Bump" to "bumptexture" and "Base" to "basetexture" and it worked.

This topic is closed to new replies.

Advertisement