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!
2 replies to this topic
Sponsor:
#2 Members - Reputation: 130
Posted 24 July 2012 - 07:08 AM
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.
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.






