Sunday, March 16, 2014

HUD/GUI with pure opengl calls

I am tired looking for good cross-platform gui libs. So far none of existing libs satisfies me.

cocos2d-x (MIT): Perfect for 2D , but I have to figure out how to draw 3D there.
librocket (MIT): Works with existing projects, but stops updating.
MyGUI-es2 (MIT): Have not tried.

I decide to reinvent the wheels.I could do GUI or HUD with only opengl calls. The basic ideal is that, draw 3D first normally, then disable depth related features and draw 2D stuff on the top. I tested with triangles, it seems working. Here is the pseudo-code.

//set your perspective matrix
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, pers_view_mat.data());

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

{
    //3D draw
}
//set your orthogonal matrix
glUniformMatrix4fv(u_matrix, 1, GL_FALSE, orthoMat.data());
{
   glDisable(GL_DEPTH_TEST);
   glDepthMask(GL_FALSE);

   //2D draw

   glEnable(GL_DEPTH_TEST);
   glDepthMask(GL_TRUE);
}

No comments:

Post a Comment