Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update examples to use new framebuffer apis #1616

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions jme3-examples/src/main/java/jme3test/post/TestRenderToTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture;
import com.jme3.texture.Texture2D;
import com.jme3.texture.FrameBuffer.FrameBufferBufferTarget;
import com.jme3.texture.FrameBuffer.FrameBufferTarget;
import com.jme3.texture.FrameBuffer.FrameBufferTextureTarget;

/**
* This test renders a scene to a texture, then displays the texture on a cube.
Expand Down Expand Up @@ -80,14 +83,25 @@ public Texture setupOffscreenView(){
offCamera.setLocation(new Vector3f(0f, 0f, -5f));
offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);

//setup framebuffer's texture
//setup framebuffer's target
// texture target -> render to texture
// create a new 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);
// create a new target that renders on this texture
FrameBufferTextureTarget colorTarget= FrameBufferTarget.newTarget(offTex);
// bind target to framebuffer as a color target (a framebuffer can have multiple color targets)
offBuffer.addColorTarget(colorTarget);
// enable MRT -> Renders on multiple color targets at the same time
// offBuffer.setMultiTarget(true);

// buffer target
// create a new buffer target
FrameBufferBufferTarget depthTarget= FrameBufferTarget.newTarget(Format.Depth);
// bind target to framebuffer as depth target
offBuffer.setDepthTarget(depthTarget);


//set viewport to render to offscreen framebuffer
offView.setOutputFrameBuffer(offBuffer);
Expand Down