Results 1 to 3 of 3

Thread: wrong transparency when drawing quads

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    4

    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 );

  2. #2
    Senior Member
    Join Date
    May 2010
    Posts
    207

    Re: wrong transparency when drawing quads

    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.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    4

    Re: wrong transparency when drawing quads

    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.

Similar Threads

  1. GL_TRIANGLES Vertices problem when attempting to draw quads
    By kris in forum Developers Coding:Beginner
    Replies: 1
    Last Post: 07-27-2011, 03:25 AM
  2. No Quads, Polygone ?
    By qasim1981 in forum OpenGL ES general technical discussions
    Replies: 1
    Last Post: 11-04-2004, 04:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •