Jump to content
  • Advertisement
Sign in to follow this  
fazekaim

OpenGL question about multitexturing with opengl shading language

This topic is 5173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 );

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
The shader render the first (GL_TEXTURE0_ARB) texture.
It is a problem through an oversight or a fatal mistake? :)

Thanks

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
OOOOOOOOOOOOhhhhhhhhhhhhhhhhhhh!

The program render only the second texture :)))
So, my question is still active:))

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!