jPCT - a 3d engine for Java > Support

Render Scene to Texture - Questions/Possibility

(1/1)

Jamiro:
Hello once again,

I've read about this particular possibility and I've tried it in the past but without any success. So I' will try it again this time until it works, so, my render loop is defined this way:


--- Code: ---   while(run){
      //-- START RENDER WORLD --//
      BUFFER.clear(back_Color);
      BUFFER.setPaintListenerState(false);
     
      *1*
     
      WORLD.renderScene(BUFFER);
      WORLD.draw(BUFFER);
      //-- END RENDER WORLD --//
     
      draw2DElements(BLIT_OBJECTS, BUFFER);
     
      *2*
     
      BUFFER.setPaintListenerState(true);
      BUFFER.update();
      BUFFER.displayGLOnly();
      canvas.repaint();
     
      *3*
     
      Thread.sleep(delay);
   }

--- End code ---

So my questions are these:


* Can I use the same FrameBuffer to render the scene to the canvas and to a texture? If so, how? and where? at position 1, 2 or 3 in the code or other?
* Can I use different FrameBuffers to render to texture as well? if so, what you suggest is better, using the same world or one world per framebuffer?
* If I want to change this texture on the go, what is the best technique to do so, and the fastest way? using shaders ou can it be done by AWT graphics way?
* And lastly, can I render it to a bitmap or any other image format in order to be saved as a file?

regards,
Jamiro

EgonOlsen:
I'll jump straight to your question:


* You use the same FrameBuffer, but with a render target being set (http://www.jpct.net/doc/com/threed/jpct/FrameBuffer.html#setRenderTarget(com.threed.jpct.Texture)).
* Because the FrameBuffer is bound to the actual output, you can't use multiple ones.
* You would have to use shaders for this, but it requires an additional step (set render target, render the scene into the texture, remove the render target, set a blitting shader (http://www.jpct.net/doc/com/threed/jpct/FrameBuffer.html#setBlittingShader(com.threed.jpct.GLSLShader)), blit the texture using your shader). AWT or any other client side image library has no access to the texture's data. It exists on the GPU only.
* Yes, but that this way. You can obtain the pixels of a rendered scene by using http://www.jpct.net/doc/com/threed/jpct/FrameBuffer.html#getPixels()

Jamiro:
Awesome, thanks

Navigation

[0] Message Index

Go to full version