views:

713

answers:

1

I apologize in advance if this question seems confused. The behaviour I am seeing makes no sense to me.

I have a Framebuffer rendering to a texture. I render solid rectangles of red, green, blue of varying opacity to this texture. I then render the texture to the screen (Framebuffer 0). The Framebuffer attached to the texture is persistent, and in each render loop I draw more rectangles to the texture -- eventually filling the screen.

I have found that if I do not set glColor() to white 100% opacity before rendering the texture to the screen, rectangles of particular colours will not be rendered. That is if glColor(1.f, 0.f, 0.f, 1.f) is set before rendering the texture, only the blue rectangles will be drawn.

I don't understand why the current colour would have an affect on the rendering of the texture (which I assume is like a blit). I have tried various texParameter(...) calls to no avail, but I am just guessing.

Thanks.

+2  A: 

Amongst other things, glColor() sets the color used for a vertex. When the textured rectangle is drawn, each texel sample is multipled by the vertex color. Well, actually, a linear interpoloation of the vertices of the primitive which is simply the vertex color if all the verticies have the same color.

This tutorial explains the implications of all this pretty well:

http://www.falloutsoftware.com/tutorials/gl/gl4.htm

The only odd part here is your statement that glColor(1, 0, 0, 1) causes only blue rectangles to be drawn. I would expect that to be only red rectangles if the parameters to glColor are red, green, blue and alpha. Hopefully there's a typo or the parameter order is different such that red = 0, green = 0, blue = 1 and alpha = 1.

George Phillips