Jump to content
  • Advertisement
Sign in to follow this  
Vorel512

GLSL multitexturing

This topic is 2187 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

Hi experts,

I am learning shader programming, and I do not know how to place a picture on another.

My obj-c code:
[source lang="cpp"] glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _fishTexture);
glUniform1i(_textureUniform0, 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _floorTexture);
glUniform1i(_textureUniform1, 0);

glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
glUniformMatrix3fv(_modelNormalUniform, 1, 0, modelView.glMatrix);

glViewport(0, 0, self.frame.size.width, self.frame.size.height);

glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);

glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex2), 0);
glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE,
sizeof(Vertex2), (GLvoid*) (sizeof(float) * 3));
glVertexAttribPointer(_normalSlot, 3, GL_FLOAT, GL_FALSE,
sizeof(Vertex2), (GLvoid*) (sizeof(float) * 7));
glVertexAttribPointer(_texCoordSlot, 2, GL_FLOAT, GL_FALSE,
sizeof(Vertex), (GLvoid*) (sizeof(float) * 10));[/source]

And my fragment shader:
[source lang="cpp"]varying lowp vec4 DestinationColor;

varying lowp vec2 TexCoordOut;
uniform sampler2D Texture0,Texture1;

void main(void)
{
gl_FragColor = mix(texture2D(Texture0,TexCoordOut),texture2D(Texture1, TexCoordOut),1);
}[/source]

Also I have the right declarations and syntax. But it displays only one of my pictures. (I have a neon green and a grey plain texture, and the grey is shown always, no matter the query...)

As far as I know the mix() function return value is computed as follows: x*(1-a)+y*a. So if I set it to 1, the second texture (Texture1) will be above the first. I do not want to calculate some colors, I want to use the images as they are, but on top of each other.

Thanx in advance!

Share this post


Link to post
Share on other sites
Advertisement
Okay, I missed '1' at the second glUniform1i(_textureUniform1, 0);
I've set the mix to the second pictures alpha channel, and now it looks much more proper. But some pixels has alpha 1... I do not know why, because the background image has alpha 255 everywhere.

Share this post


Link to post
Share on other sites
But some pixels has alpha 1... I do not know why, because the background image has alpha 255 everywhere.[/quote]
No idea what that means. Post a pic. If its not blending you have to still call glEnable(GL_BLEND);

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!