I have this 3D model visualizer that produces 3D Models starting from Disparity Maps, here is an example:
Input:
Output:
The 3D visualizer is written in OpenGL and GLUT, in particular the whole code can be found here:
https://github.com/lpuglia/DisparityVisualizer
The model is built using GL_TRIANGLE_STRIP
in GL_VERTEX_ARRAY
. This article explains a way to reproduce my model:
http://www.learnopengles.com/tag/vbos/
In particular i use the following code as display function:
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );
glVertexPointer( 3, GL_FLOAT, 0, vertices );
glColorPointer( 4, GL_FLOAT, 0, colors );
glDrawElements( GL_TRIANGLE_STRIP, getIndicesCount(width,height), GL_UNSIGNED_INT, indices );
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_COLOR_ARRAY );
I'm experiencing problems with the management of transparency, at the moment I'm using this code for the initialization:
glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
As you may have already notice the glColorPointer
function is used with 4 channels, in fact, i use the 4th channel to set the alpha of the points at the edge of objects (marked in blue here):
This approach seems to works but not for every angle (?) as you can notice in this animation:
Tilting the model from up to down makes the transparent edges appear and disappear even though nothing has changed in the alpha channel, I suspect a problem between the depth and transparency or something related to that, but i have no idea of how to solve this. Can you help me?
So apparently for my purpose I don't need any blending, I just need Alpha ON and OFF, something that I can simply do replacing:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
With:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_EQUAL, 1.0);