I am trying to display a HUD on top of an OpenGL ES 2.0 application written in C on an ARM Linux platform.
Currently, I am using 2 triangles located close to the clipping plane and laying texture on them. Texture is the size of the screen and is mostly transparent, with the exception of those parts where I have text. Texture created with Pango / Cairo
If I turn on the HUD (uncomment the render_ui call), I am currently getting a 50% performance hit (going from 60 frames per second to 30 frames per second).
Here is the code to display the HUD:
void render_ui(OGL_STATE_T *state) { glUseProgram(state->uiHandle); matIdentity(modelViewMatrix); matTranslate(modelViewMatrix, 0, 0, -0.51); const GLfloat *mvMat2 = modelViewMatrix; glViewport(0,0,state->screen_width, state->screen_height); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBindBuffer(GL_ARRAY_BUFFER, state->uiVB); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, state->uiIB); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, state->uiTex); glUniform1i(_uiTexUniform, 0); glUniformMatrix4fv(_uiProjectionUniform, 1, 0, pMat); glUniformMatrix4fv(_uiModelViewUniform, 1, 0, mvMat2); glVertexAttribPointer(_uiPositionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0); glVertexAttribPointer(_uiColorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *) (sizeof(GLfloat) * 3)); glVertexAttribPointer(_uiTexCoordSlot, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid *) (sizeof(GLfloat) * 7)); glEnableVertexAttribArray(_uiPositionSlot); glEnableVertexAttribArray(_uiColorSlot); glEnableVertexAttribArray(_uiTexCoordSlot); glDrawElements(GL_TRIANGLES, uiIndicesArraySize / uiIndicesElementSize, GL_UNSIGNED_BYTE, 0); glDisableVertexAttribArray(_uiTexCoordSlot); glDisable(GL_BLEND); GLenum err; if ((err = glGetError()) != GL_NO_ERROR) printf("There was an error"); }
There should be a smarter way to do this.