Re: Seeking Help with OpenGL Depth Buffer Issue
Posted by
xghost on
Oct 05, 2014; 12:39am
URL: https://forum.jogamp.org/Seeking-Help-with-OpenGL-Depth-Buffer-Issue-tp4033219p4033270.html
Hi,
I apologize for the delayed response. It was a busy week. I had a chance to get the code to run and, as expected, it displayed the darker triangle in front of the lighter colored one. Disabling depth testing also produces the expected result of the last object to be drawn always being in front. (My project has depth testing enabled, uses the same depth function, and clears the depth buffer on every display, so we seem to be good there.)
I modified the sample code you provided in a few ways and I noticed some things that I'll mention briefly. The modifications boil down to making a few things more similar to the project I'm working on. These include:
1. Splitting the triangle vertex position arrays into 2 separate VBOs;
2. Updating the fragment depth values to make one triangle switch between being at the front/back;
The full diff for the sample is here:
triangle-sample.diffOne thing I noticed is that I had to add an offset attribute to the vertex shader of the sample code so that I could use it to update the Z component of the position vector. For this sample code, this does not seem unexpected because their actual positions are not being transformed --i.e. the triangles do not move around within the coordinate space.
In my project, however, the objects do move around in 3D space. I guess I still don't expect this is what I really need to do (i.e. add an offset attribute to my vertex shader) because I'm already using a vertex uniform (i.e. model_matrix) to store the transformations for the object I wish to render.
Am I wrong to think that this is supposed to be enough? The model_matrix uniform already holds the translation/rotation/scale transformations for the object, so why would I need to add something else? I guess that's why I'm thinking that the root-cause might still be elsewhere... but I'm clearly still missing something here, so help is still appreciated.
Thanks in advance.