Oh! I found it! Yeah, the TestRendertoTexture example.
It is actually one of the ones I’m studying now. It boils down to setup a camera, viewport, texture(to receive the “color” or “diffuse” map) and then attaching the texture to a framebuffer, which is then attached to the renderManager of your app as a PreView.
that scene is now rendered before a “MainView” in the rendering pipeline. The “magic” of the setup is in this method:
[java]
// these two declarations are part of the bounding class’s globals
private Geometry offBox;
private ViewPort offView;
public Texture setupOffscreenView(){
Camera offCamera = new Camera(512, 512);
offView = renderManager.createPreView("Offscreen View", offCamera);
offView.setClearFlags(true, true, true);
offView.setBackgroundColor(ColorRGBA.DarkGray);
// create offscreen framebuffer
FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
//setup framebuffer's cam
offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
//setup framebuffer's texture
Texture2D offTex = new Texture2D(512, 512, Format.RGBA8);
offTex.setMinFilter(Texture.MinFilter.Trilinear);
offTex.setMagFilter(Texture.MagFilter.Bilinear);
//setup framebuffer to use texture
offBuffer.setDepthBuffer(Format.Depth);
offBuffer.setColorTexture(offTex);
//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
// setup framebuffer's scene
Box boxMesh = new Box(Vector3f.ZERO, 1,1,1);
Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
offBox = new Geometry("box", boxMesh);
offBox.setMaterial(material);
// attach the scene to the viewport to be rendered
offView.attachScene(offBox);
return offTex;
}
[/java]
notice that you can make an entire scene to be rendered this way… in the example, the material is a simple unshaded type. (logo.j3m)
then you can access it for another geometry like a Quad in the material setup.
[java]
Texture offTex = setupOffscreenView();
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", offTex);
quad.setMaterial(mat);
[/java]
and because any scene you create in a pre View should be constructed fully lit… the texture should always be considered a “color” or “diffuse” map if used on a geometry.
(edit) the code is snipped from the example, no javadoc to accredit original authorship (edit)
hope that helps.