Creating a Background Image with clear color buffer

I am trying to create a stationary background image like done here:

But I can’t set the viewPort’s clear color buffer to false because i’m using the oculus rift which requires it to be true.
Is there any other way I could create a background from an image? or maybe a way I could do the above but with clear color buffer to true?

Hm a more hacky approach:

A large quad that you move always in front of the camera (but near the far frustrum), and scale so its always fullscreen.

And afaik its recommended to not have static images with the oculus, not even for menus etc.

Well I’m trying to put a changing image from a camera on it from the leap motion on it so you see what is in front of you so it wouldn’t be a static image.

I tried to create a quad like you suggested before but when using the OVRApplication it doesn’t show up. But a Box with 0f as the z size works. But now the problem is how do I transfer from pixels from cam.getWidth() to world Units?

Camear near frustrum, far frusturm and pyxramid like thing between (see how the frustrum culling does it)

With that you should be able to calculate the necessary size of the quad. (I suck at math however, i only know that this should be solveable)

There are a couple of ways you can tackle this.

One is to create a filter that displays the image.

Secondly, you can create a quad and use attachScene on each viewPort. Then rotate it to always face the camera (lookAt(cam.getLocation))

Edit: With the second approach, you most likely has to move it to always be in front of the camera as well. (setLocalTranslation(cam.getDirection())

Correct me if i’m wrong but shouldn’t cam.getFarrustrum()/(cam.getWidth*cam.getHeight) get the number of world units per pixel?

Thanks guys, I figured it out xD
This is how I created one for camera named cam with a Material named backMat.

You have to use the derived fovY for the camera because the oculus rift’s 110 degrees is too large

It’s more acurate to calculate the fovX as well instead of the aspect of the camera size

// Frustums Used
float top = cam.getFrustumTop();
float right = cam.getFrustumRight();
float near = cam.getFrustumNear();
float far = cam.getFrustumFar();

// derive fovY & fovX value
float fovY = FastMath.atan(top / near)
/ (FastMath.DEG_TO_RAD * .5f);
float fovX = FastMath.atan(right / near)
/ (FastMath.DEG_TO_RAD * .5f);

// derive height & width of FrustumFar
float height = 2farFastMath.tan(fovX/2);
float width = 2farFastMath.tan(fovY/2);

// Create the background
Box backgroundBox = new Box(width,height,0f);
background = new Geometry(“Background”, backgroundBox );

// Set the background to the correct distance from the camera
background.move(0, 0, cameraCam.getFrustumFar()-0.1f);

// Attach it to a node that moves and rotates with the camera

1 Like

My only problem now is that I would like to set an object to for each of two different viewports like rickard suggested but when I do I get an error saying “State was changed after rootNode.updateGeometricState() call. Problem Spatial: cameraNodeLeft”
Is there anyway I could fix that?

cameraNodeLeft is the node following the camera of the left ViewPort that the background on the left is attached to.

If you have seperate scenes in a different viewport, you need to update/manage them manually.

I’m sorry, I’m actually new to jmonkey. How would I update/manage a scene in a viewport?

@NecrpTheif said: I'm sorry, I'm actually new to jmonkey. How would I update/manage a scene in a viewport?

Check the source of SimpleApplication, especially the update method:

Edit: Created a “RootNodeAppState” in master which manages a RootNode with a given (or the default) ViewPort:

Thanks a lot! :slight_smile:
I didn’t end up using the RootNodeAppState you made but it helped me to figure out i just had to add


to the end of my simpleUpdate method. Thanks again

I was defining the backgrounds in the simpleUpdate since the OVRAppState had to be initialized to get the viewPorts but i just used the default camera to create them in the simpleInitApp method and added the to the viewPorts in the simpleUpdate method since they wouldn’t show up if I created them in the simpleUpdate method.