Wednesday, July 22, 2009

glTexEnvi and GL_REPLACE

So I wanted something really simple. A textured object (with alpha channel) and I wanted it to fade it out, and perhaps color it at run time (instead of creating different colored textures).

I knew that I should just give the object texture coordinates, and color information (besides vertex positions). Simple but it wasn't working. It was like it was not taking into consideration the color info at all. So I played around with a demo which I use as my playground and the same code worked. I was going nuts and it was obvious I was missing something. I was looking at the gl commands in the demo, and I had done all of those - enabling blending, enabling textureing, enabling vertex/texture/color arrays, blending function etc. Still nothing. It then clicked that by default it must be working automagically in the demo, and I must have some line of code which is changing the default behaviour and I spotted that line of coding which was setting the texture mode in glTexEnvi to GL_REPLACE which basically will discard the color information. I had completely forgotten about what that line was doing. Ah well...

No comments: