ofEnableDepthTest() and .png ofImage

Hi guys
I am not quite sure if it’s a bug
But I have a 3d model loaded in the scene with ofxAssimp.

Here is my code is really simple

void ofApp::setup()----------------
ofDisableArbTex();
ofEnableAntiAliasing();
model.loadModel("ironman.dae", true);
logo.loadImage("media/logo.png");
frame.loadImage("media/frame.png");

void ofApp::draw()--------------
ofEnableDepthTest();
glShadeModel(GL_SMOOTH);
model.drawFaces();
logo.draw(0,0);
frame.draw(0,0);

If i use ofEnableDepthTest() the 2 images (ofImages) won’t display
If I don’t use ofEnableDepthTest() the 3d model will look terrible with big black unwanted area.

Is that a bug or i did something wrong?

hey @peko!

DepthTest will make sure that 3d elements that are covered by other elements won’t be rendered. The GPU will use the depth buffer to figure out whether a pixel is in front or behind something that’s already displayed on your screen. When you render your 3d scene, that’s generally what you want.

When you render images on top of your scene, however, depth testing can lead to all sort of weird behaviour, if you have already rendered other things to your screen. This is because openFrameworks renders everything in 3d, even images. When you draw an image, two triangles are rendered into your 3d scene, facing the camera. These two triangles form a rectangle which is textured using your image so that it looks as if your image was lying flat on the screen.

But because that rectangle is drawn in 3d, it might end up being rendered behind your model, in which case the depth test will make sure that it gets hidden behind your 3d model. To make sure to render your image whatever happens, you would generally switch off depth testing before drawing an image that you want to see on top of everything.

Try disabling depth testing just before you render your images. After you draw your model. In the next line after model.drawFaces(), issue:

ofDisableDepthTest();

My bet is that this will do the trick.

1 Like

Is this ok?

void ofApp::setup()----------------
ofDisableArbTex();
ofEnableAntiAliasing();
model.loadModel("ironman.dae", true);
logo.loadImage("media/logo.png");
frame.loadImage("media/frame.png");

void ofApp::draw()--------------
ofEnableDepthTest();
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LESS); //added line 1
model.drawFaces();
glDepthFunc(GL_ALWAYS); //added line 2
logo.draw(0,0);
frame.draw(0,0);
ofDisableDepthTest(); //added line 3
1 Like

@tgfrerer
thanks a lot for the explanation :smile:
I fully understand what was the problem

   ofDisableDepthTest();

@Rancs thanks a well I added your lines as well
and it worked great :smile:

thanks a lot guys