How draw a background in OF ?

Hi, I try draw a static background in screen ( behind 3d model ) but it always before the model. I call draw background image before call draw 3d model ( :smiley: astroboy form OF sample ) why it always before the model
Please, see the file attach, what am I mistake ?.

  
  
void testApp::draw(){  
    imgBG.draw(0,0,300,200);  
  
    cam.begin();  
    ofPushMatrix();  
		//ofTranslate(model.getPosition().x+100, model.getPosition().y, 0);  
		ofRotate(-mouseX, 0, 1, 0);  
		//ofTranslate(-model.getPosition().x, -model.getPosition().y, 0);  
  
		model.drawFaces();  
  
    ofPopMatrix();  
    cam.end();  
  
    ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);  
    ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 30);  
}  
  

file testApp.h

  
  
#include "ofMain.h"  
#include "ofxAssimpModelLoader.h"  
class testApp : public ofBaseApp{  
  
	public:  
		void setup();  
		void update();  
		void draw();  
  
		void keyPressed  (int key);  
		void keyReleased(int key);  
		void mouseMoved(int x, int y );  
		void mouseDragged(int x, int y, int button);  
		void mousePressed(int x, int y, int button);  
		void mouseReleased(int x, int y, int button);  
		void windowResized(int w, int h);  
		void dragEvent(ofDragInfo dragInfo);  
		void gotMessage(ofMessage msg);  
  
		ofImage imgBG;  
  
		bool bAnimate;  
		bool bAnimateMouse;  
		float animationTime;  
        ofxAssimpModelLoader model;  
  
        ofLight	light;  
        ofEasyCam cam;  
};  
  

many thanks ^_^.

I could not test your example with model included, but I think this has to do with depth. In my case your code works fine with a simple sphere, instead that with a model.

Did you enable depth with glEnable(GL_DEPTH_TEST) or does your model change depth in any way?

There might be an emergency solution: glDepthFunc. If you set it to GL_ALWAYS, and apply it to your model, the pixels of the model, always pass the depth test so they are drawn in front. Afterwards you have to set it back to “normal” GL_LESS mode. Let me know if it works.

  
  
  
void setup() {  
glEnable(GL_DEPTH_TEST);  
}  
  
  
void draw() {  
     imgBG.draw(0,0,300,200);   
        
  
    cam.begin();    
	  
	ofRotate(-mouseX, 0,1,0);  
  
	//just a random sphere  
        glDepthFunc(GL_ALWAYS);  
	ofPushStyle();  
	    ofSetColor(1.0f, 0.0, 0.0f);  
	    ofSphere(0.0f, 0.0f, 0.0f,300.0f);  
	ofPopStyle();	  
       glDepthFunc(GL_LESS);  
  
    cam.end();  
  
}  
  

thz @glBeatriz for rely. It’s make me can find the path :D.
I try with “glDepthFunc(GL_ALWAYS)” … “glDepthFunc(GL_LESS)” the model is still the back of background. When I remove glEnable(GL_DEPTH_TEST); in setup() the model become to the font :-/ . But model is seethought to poly ( see attach file ).
I changed glEnable(GL_DEPTH_TEST) … glDisable(GL_DEPTH_TEST) model become draw :smiley: perfect. What diff beween with glDepthFunc(GL_ALWAYS) vs glEnable(GL_DEPTH_TEST). it’s more confuse :-?

  
  
void testApp::draw(){    
    imgBG.draw(0,0,300,200);    
    
    cam.begin();   
    glEnable(GL_DEPTH_TEST);  //glDepthFunc(GL_ALWAYS);   
    ofPushMatrix();    
        //ofTranslate(model.getPosition().x+100, model.getPosition().y, 0);    
        ofRotate(-mouseX, 0, 1, 0);    
        //ofTranslate(-model.getPosition().x, -model.getPosition().y, 0);    
    
        model.drawFaces();    
    
    ofPopMatrix();    
    glEnable(GL_DEPTH_TEST);  //glDepthFunc(GL_LESS);  
    cam.end();    
    
    ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15);    
    ofDrawBitmapString("num animations for this model: " + ofToString(model.getAnimationCount()), 10, 30);    
}  
  

Sorry for me ask a question :stuck_out_tongue: : how set projectionMatrix for ofCamera :-? i found getProjectionMatrix() but not found setProjectionMatrix in ofCamera.
cheer, thz u so much ^_^.