Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

GLSL multitexturing

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Vorel512   Members   

130
Like
0Likes
Like

Posted 24 July 2012 - 06:54 AM

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 Vorel512   Members   

130
Like
0Likes
Like

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.

#3 dpadam450   Members   

2332
Like
0Likes
Like

Posted 24 July 2012 - 10:04 AM

But some pixels has alpha 1... I do not know why, because the background image has alpha 255 everywhere.

No idea what that means. Post a pic. If its not blending you have to still call glEnable(GL_BLEND);




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.