What I have done so far is a 3d cylinder object. Next I want to color it so that the top and bottom would be blue and the side would be red. I have no idea how to achieve that.
I know that there are two types (or maybe more) coloring techniques: flat coloring (with gl.glColor4f()) and smooth coloring (with gl.glColorPointer() using the colorBuffer).
I think what I want to use is flat coloring. I have done it so:
- Code: Select all
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
// blue top and bottom
gl.glColor4f(0.3f, 0.1f, 0.9f, 1f);
// red side
gl.glColor4f(0.9f, 0.1f, 0.1f, 1f);
The indexBuffer1 contains all the indices of top and bottom, and indexBuffer2 contains the indices of the cylinder side wall.
The problem is that when I draw top/bottom and side separately, to change the color, strange thing happens. The red side is overlapping on the blue surface one, just as if the blue would be transparent. If I draw blue parts afterward, the effect is reversed.
Result looks like that:
All the help is very welcome.