开发者

Adding a decal using multitexturing on an iPhone

开发者 https://www.devze.com 2022-12-13 23:18 出处:网络
I\'m trying to overlay one image on top of another onto a simple quad. I set my bottom image as texture unit 0, and then my top image (which has a variable alpha) as texture unit 1. Unit 2 has mode GL

I'm trying to overlay one image on top of another onto a simple quad. I set my bottom image as texture unit 0, and then my top image (which has a variable alpha) as texture unit 1. Unit 2 has mode GL_DECAL, which means the bottom texture should show up when the alpha is 0, and the top texture should show when the alpha is 1. But, only the top texture shows up and the bottom one doesn't appear at all. It's just white where the bottom texture should show through.

glGetError() doesn't report any problems. Any help is appreciated. Thanks!

glVertexPointer(3, GL_FLOAT, 0, boxVertices);
glEnableClientState(GL_VERTEX_ARRAY);

glClientActiveTexture(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, boxTextureCoords);
glClientActiveTexture(GL_TEXTURE1);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, boxTextureCoords);

glClientActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glClientActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);

glClientActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, one.texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glClientActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, two.texture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glD开发者_StackOverflowrawArrays(GL_TRIANGLE_FAN, 0, 4);


Since you're using vertex arrays, you need to use glClientActiveTexture instead of glActiveTexture when setting your texture coords.

0

精彩评论

暂无评论...
验证码 换一张
取 消