Search Unity

glDrawArrays vs immediate mode drawing, in a C++ plugin

Discussion in 'Editor & General Support' started by brianchasalow, Aug 4, 2011.

  1. brianchasalow

    brianchasalow

    Joined:
    Jun 3, 2010
    Posts:
    208
    let's say I'm just drawing a simple quad. glDrawArrays never seems to work properly, whereas glTexCoord2f + glVertex2f always does. Any of the Unity engine programmers have any idea why?

    for example, this never works in a plugin in Unity, even if i push/pop GL_CLIENT_ALL_ATTRIB_BITS - (non-relevant code has been excluded). Sometimes it will draw a black quad, other times nothing at all:
    Code (csharp):
    1.     glEnableClientState( GL_TEXTURE_COORD_ARRAY );
    2.     glTexCoordPointer(2, GL_FLOAT, 0, tex_coords );
    3.     glEnableClientState(GL_VERTEX_ARRAY);      
    4.     glVertexPointer(2, GL_FLOAT, 0, verts );
    5.     glDrawArrays( GL_TRIANGLE_FAN, 0, 4 );
    6.     glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    7.     glDisableClientState(GL_VERTEX_ARRAY);
    8.  
    but this works just fine:
    Code (csharp):
    1.     glBegin(GL_QUADS);
    2.     glTexCoord2f(tex_coords[0], tex_coords[1]);
    3.     glVertex2f(verts[0], verts[1]);
    4.     glTexCoord2f(tex_coords[2], tex_coords[3]);
    5.     glVertex2f(verts[2], verts[3]);
    6.     glTexCoord2f(tex_coords[4], tex_coords[5]);
    7.     glVertex2f(verts[4], verts[5]);
    8.     glTexCoord2f(tex_coords[6], tex_coords[7]);
    9.     glVertex2f(verts[6], verts[7]);
    10.     glEnd();
     
    Last edited: Aug 5, 2011