How can I create background images in OpenSceneGraph?

I'm trying my hand at using OpenSceneGraph for graphics in my game. I'm having a hard time trying to figure out how to get a background image up. The relevant piece of code that I have can be found in this gist. Does anyone here have an idea of what I'm doing wrong/missing?

BTW:

1. I know that the image is getting loaded because the logs says so
2. The log says that it managed to add the camera as slave to the viewer
• It's unclear what you want to do. You may get better solutions to your issue if you give more details. What do you mean by "background image" and what's going to be on the foreground? – Vaillancourt Nov 14 '15 at 16:19
• I maybe using the wrong terminology here. I want an image that will always be behind the current scene and always faces the camera. The image itself should fill the background of the scene. Think of it like a wallpaper in your desktop. If the image doesn't match the resolution, it should stretch to fill the background. Does that make sense? – Vite Falcon Nov 14 '15 at 17:50

I was able to solve my issue. The second revision of my gist has the solution. In a nutshell, this was what I did:

1. Create a camera
2. Set the view matrix of the camera to identity so that there are no view transforms made to the children
3. Set the projection matrix of the camera to be of an orthogonal matrix with width and height equal to 1
4. Set resize policy on projection matrix to be fixed
5. Set render order to be NESTED_RENDER (I previously had this as PRE_RENDER and that didn't work. I still have to dig into why).
6. Create a textured quad with width and height of 1 unit
7. Add the textured quad to an instance of osg::Geode and add that geode to the camera
8. Extract the first window from the camera. Set the graphics-context and viewport of the camera
9. Add the camera to the scene and you have a background image

I was unable to find a good working code for this simple thing. Luckily I got this working. I hope this helps someone else who's trying to do the same.

P.S.: If you want to displace the background image on the screen, think of doing that in relative values; [0, 1]. So if you want the background image to be on the top-right of the screen, create the texturedQuad like so:

auto texturedQuad = osg::createTexturedQuadGeometry(
osg::Vec3(0.5f, 0.5f, 0.f), // Corner
osg::Vec3(0.5f, 0.f, 0.f),  // width
osg::Vec3(0.f, 0.5f, 0.f),  // height
0.f,
0.f,
backgroundImage->s(),
backgroundImage->t());