Hi all, first post here !
I’m currently reading the red book and juste finished reading chapter 2 on the different options for drawing geometric data.
Also, I’m working on a UI Toolkit (Game Interface) in OpenGL-ES (I know I do not have all the options shown in the red book) and I’m trying different drawing options without really knowing what was best performance wise. I tried glDrawArrays and glDrawElements, both working and I think it might be better using glDrawElements since I do not have to specify multiple time the same vertex.
Since I’m doing a UI kit, I do not have a lot of vertex but still would like to use the best technique. Right now, I’m rendering my Component (like a button, frame, slider, label, etc) individually. Here is the code :
if(mSprite != NULL && mSprite->texture != NULL && mSprite->texture->validData)
{
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(2, GL_FLOAT,0,vertices);
glTexCoordPointer(2, GL_FLOAT, 0, mSprite->texCoords);
glColor4f(mColor.mRed, mColor.mGreen, mColor.mBlue, mColor.mAlpha);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mSprite->texture->textureID);
if(mSprite->texture->transparency)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
{
glDisable(GL_BLEND);
}
glTranslatef(mPos.x + mVisualPositionOffset.x,mPos.y + mVisualPositionOffset.y, 0.0f);
glScalef(mSize.x*mScale.x + mVisualSizeOffset.x, mSize.y*mScale.y + mVisualSizeOffset.y, 1.0f);
// glDrawArrays(GL_TRIANGLES, 0, 6);
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_SHORT,indices);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
//Reset Matrix for next use
glLoadIdentity();
}
And here the arrays I’m using :
static const GLfloat vertices[] =
{
0.0f, 0.0f,
0.0f, -1.0f,
1.0f, -1.0f,
1.0f, 0.0f
};
static const GLushort indices[] = {0,1,3, 3,1,2};
So any recommendation would be welcome !