Render to Texture

Hey jME fans,

The first cut of Render to texture is done and up with a nice demo test. (See jmetest.renderer.TestRenderToTexture)

To use it, you need to do the following:

  1. Get a video card that supports Pbuffers… I believe this includes most cards from 1998 and above, but don’t have many of those to test on :slight_smile:
  2. in your code, setup the texturerenderer and a texture to use:

        LWJGLTextureRenderer tRenderer;
        Texture fakeTex;

..... later in initGame() ........
        tRenderer = new LWJGLTextureRenderer((LWJGLRenderer)display.getRenderer());
        tRenderer.setBackgroundColor(new ColorRGBA(.667f, .667f, .851f, 1f));
        fakeTex = tRenderer.setupTexture();

3. Apply the texture to whatever your are texturing in the normal manner:

        TextureState ts = display.getRenderer().getTextureState();

4. In render(), call the TextureRenderer and pass in the node to render to texture and the texture you set up in step 2. Do this before rendering the scene that will contain that Texture:

        tRenderer.render(fakeScene, fakeTex);

That's it. Let me know if you have any problems or suggestions![/code]

Looking good! After Eric’s update tonight, we’ll get that in the demos area as well.

Thought I’d add two things to this thread.

  1. Texture was being squished horizontally due to an improper default frustrum setting. Sorry! Fixed.

  2. You can now better control the camera used in rendering the texture scene. (Thanks to Mojo for pushing the envelope with his awesome camera man demo…) I’ve fixed it up so you can do things like attach the render camera to a controlled node, etc. As usual, if you grab the camera in your code and change settings, make sure the camera gets updated.

    There are some pretty cool things you can do with render to texture, mirrors, reflections, video display, imposters… and probably a lot I can’t think of now. Some of those things can be done better with other techniques which I’m sure will be part of jME in the future, but right now this is pretty easy. :smiley:

Speaking of which, the demos are up on the demo page. So, if you haven’t already check them out.

Hmmm interesting finding… when trying to run the demos on my work computer, it hits the PBuffer support detected printout and then shuts down. No error/exception is logged, just exits. This is on a:

P4 2.2 GHz, GeForce 3, Win 2K.

Works fine via webstart on my laptop.

Another little isse (minor) if 640x480 is selected in Camera Man some junk is displayed at the top of the texture.

Ran it on a second computer that the PBuffer stuff crashes. Not sure what’s going on there. Maybe it’s related to the issue on the javagaming forums?

Quick note, you access the TextureRenderer now through DisplaySystem, thus allowing you to use it without specifying the underlying type (like LWJGL)


tRenderer = display.createTextureRenderer(false, true, false, false, TextureRenderer.RENDER_TEXTURE_2D, 0);

Also, if your card supports rendering directly to texture, that will be used. It’s a little bit faster in the two tests we have so far.

Ok, just ran the newest version on the work computers…

The one with the geforce 3 works now, when it didn’t before, but the one with the geforce 2 still doesn’t work.