Wrong transparency when drawing quads

Hi,
I am using 5 points to draw a quad in opengles. Everithing is ok, but when I am trying to apply some transparency to this quad, using glColor4f the transparency/color is not uniform, I can clearly see the delimitation between the two triangles.
Is something wrong in my code?

GLfloat test_vertices[] = {
-1, -1, 0, // 1
1, -1, 0, // 2
-1, 1, 0, // 3
1, 1, 0, // 4
1, -1, 0 // 5(2)
};
for(i=0;i<15;i++)
test_vertices[i] *= aspect_ratio;

GLfloat test_uv[] = {
	0, 1.0 - height_aspect_ratio,
	width_aspect_ratio, 1.0 - height_aspect_ratio,
	0, 1,
	width_aspect_ratio, 1,
	width_aspect_ratio, 1.0 - height_aspect_ratio
};

glVertexPointer		( 3, GL_FLOAT, 0, test_vertices );
glTexCoordPointer	( 2, GL_FLOAT, 0, test_uv );
glEnableClientState	( GL_VERTEX_ARRAY );
glEnableClientState	( GL_TEXTURE_COORD_ARRAY );

z_distance = (test_vertices[3] - test_vertices[0]) / 2.0f / tan(FOV/2*DEGREES_TO_RADIANS);

glLoadIdentity	();
glTranslatef	( 0, 0, -z_distance );

if(tex_buffer==0)
	egl_createTextureFromFile( "test_img/fluture2.bmp", &tex_buffer );

glBindTexture	( GL_TEXTURE_2D, tex_buffer );
    glCOlor4f            ( 1.0f, 1.0f, 1.0f, 0.5f );
glDrawArrays	( GL_TRIANGLE_FAN, 0, 5 );

glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState( GL_VERTEX_ARRAY );

Your “fan” mesh overlaps itself - you need to plot it out on graph paper by hand to see what’s going on…but you’re drawing three triangles - the first is the bottom-left half of the square, the second is the top-left half and the third triangle is the bottom-right. Since they are all at the same Z, they are all flimmering against each other.

Thank you Steve, that was the problem.
I have changed the array to
GLfloat vertCoords[] = {
-1, 1, 0,
-1, -1, 0,
1, -1, 0,
1, 1, 0,
-1, 1, 0
};
and everything looks good now.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.