3d model over background image

I saw this question here, but I don’t think it answered the same thing. (ofEnableDepthTest() and .png ofImage )

I have some objects I would like to place in a ‘room’. The room is a photograph of the inside of a store front undergoing renovations. I would like to render som e3f shapes as if the are ‘floating’ in the room. I was hoping to use an easy cam to get the 3d scene lined up over the image.

I cannot seem to be able to display the 3d image overtop of the 2d image. It ‘feels’ similar to the question I saw earlier, but I was wondering if I should render the 3d image to an FBO with transparency and then just display that over top of the background? I understand that this may affect frame rates, however.

Since the room has items within it (poles, boxes, pillars, railings) the floating objects have to be able go in front of them or behind them, so I will be adding models within the screen and adding the background image as a texture to the stationary objects so they mimic reality. I’m just having trouble displaying that background image…

s’okay, after paling around, I found this solution. Place this BEFORE your call to any easy cam.
backdrop is an ofxPlanePrimitive.
background is an ofImage loaded from a file in setup.

ofEnableLighting();

ofDisableDepthTest();
///draw the backdrop
ofPushMatrix();
ofTranslate(ofGetWidth()/2,ofGetHeight()/2,0); 
ofSetColor(255); //will be black if this is not included 

background.getTexture().bind();
backdrop.resizeToTexture(background.getTexture());
backdrop.set(ofGetWidth(), ofGetHeight());
backdrop.draw();
background.getTexture().unbind();
ofPopMatrix();
ofEnableDepthTest();

//ofEnableAlphaBlending();
ofEnableDepthTest();
cam.begin();

There is one caveat to this, however. My background image is VERY dim, like a semiopaque black background is overtop. How can I brighten it up a bit?

This is the image AFTER I brightened it in preview to make it brighter. There was no change in the dimness of it in my openframeworks program.

ah, okay … I need to use a material with emissive properties, so the image glows.

in .h file

ofMaterial thisMaterial; 

in .cpp file setup

thisMaterial.setEmissiveColor(ofFloatColor::white);
thisMaterial.setShininess(0.5); //not sure if this is necessary

in .cpp file draw

thisMaterial.begin();

background.getTexture().bind();
backdrop.resizeToTexture(background.getTexture());
backdrop.set(ofGetWidth(), ofGetHeight());
backdrop.draw();
background.getTexture().unbind();

thisMaterial.end();

Make sure you are not enabling lighting when you draw the image

actually, I just tested that. When the material/binding procedure I posted is used, it doesn’t matter when enable lighting is done, before or after. If enable lighting occurs after AND the material IS NOT used, the image is still dim.

I don’t think the placement of enable lighting was the key here.

Are you disabling lighting too?

all of the scene rendering is being done in a function. at the end of the function I am disabling lighting, depth testing and alpha blending

ofPopMatrix();
cam.end();

ofDisableLighting();
ofDisableDepthTest();
ofDisableAlphaBlending();
} //end of function

so yes, lighting is disabled before the background is drawn. I just checked, though, and if lighting was not disabled before hand, the background is still visible and properly lit when an emissive material applied. The emissive material solved the problem, not when/how lighting is enabled/disabled.

For the record, tho’, if disableDepthTesting is NOT done before drawing the background, any objects drawn within cam.begin()/cam.end() may be rendered behind the plane, so that MUST be disabled before the background is drawn.

if you disable lighting and don’t apply any material before drawing the image as @Hennio points out, the image will be drawn correctly too. also if you disable depth testing before drawing the background image, you can also just draw the image itself without having to texture map a plane with it

Sorry. Pressed reply on an email without typing.

Im going to make a test app to showcase what works and what doesnt because the solutions people are suggesting were not working as described

I tracked down the problem with ‘why’ it wouldn’t work for the background drawn as an image before any 3d related things, which was my original problem. The last part of the main loop included a setColor(0); before drawing some text.

After the first frame, the background image was being drawn with that colour, as black. Hence it created nothing but confusion on my part as to what was causing the image to not work, and led me down a rabbit hole that provided an alternative solution (emissive material) to what wasn’t ‘really’ the problem. placing setColor(255); before drawing the image before doing any 3d related things resolved that.

And, to make matters even ‘worse’ one of the lights I had was in just the right position to light the image properly if lighting was enabled before drawing the background image, so the whole enabling/disabling for lighting seemed to be irrelevant.