www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: ppparkje on August 18, 2012, 05:11:33 pm

Title: Print framebuffer to image and append texture
Post by: ppparkje on August 18, 2012, 05:11:33 pm

Hello.

I'm trying to implement a kind of viewport using multiple worlds and framebuffers.

I got a idea from this forum.(http://www.jpct.net/forum2/index.php/topic,682.msg3606.html#msg3606)

but I had a problem about that. This image doesn't made well.


How did I make viewport is:

1. render viewport to buffer
2. make BufferedImage from buffer
3. make texture from BufferedImage
4. set texture to main world plane

and here is part of my code

Code: [Select]
public Viewport(int x, int y, int width, int height) {

m_rect.setBounds(x, y, width, height);
m_world = new World();
Camera m_cam = m_world.getCamera();

...

Config.useFramebufferWithAlpha = true;
m_buffer = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
m_buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
}

private Texture toTexture()
{
BufferedImage img = new BufferedImage(m_rect.width, m_rect.height, BufferedImage.TYPE_INT_ARGB);
m_buffer.clear(new Color(0, 0, 0, 0xff));
m_world.renderScene(m_buffer);
m_world.draw(m_buffer);
m_buffer.display(img.getGraphics());

Texture t = new Texture(img, true);
t.setClamping(true);
return t;
}


For test, I drew a diagonal line on it(square viewport).

(http://ifh.wo.tc/g/VnQhC.png)

I expected transparent background viewport with some colored(not transparent) line on it, but interestingly, it blitted transparent line.

it seems that alpha channel affects entire image. when I clear the buffer with alpha 0, the viewport never show as same as line on viewport.

how can i fix this problem?
Title: Re: Print framebuffer to image and append texture
Post by: EgonOlsen on August 18, 2012, 09:49:33 pm
Try to set Config.useFramebufferWithAlpha=true; before creating the FrameBuffer and see if that helps.
Title: Re: Print framebuffer to image and append texture
Post by: ppparkje on August 19, 2012, 06:02:36 am
Quote
Try to set Config.useFramebufferWithAlpha=true; before creating the FrameBuffer and see if that helps.

in the code I pasted above,  Config.useFramebufferWithAlpha=true; is set before creation of framebuffer.

did I do something wrong?
Title: Re: Print framebuffer to image and append texture
Post by: ppparkje on August 20, 2012, 06:35:36 am
Ok.. I solved the problem.

the problem is the Object3D's transparency value. I set the value as 0xff by Object3D.setTransparency function.

When I changed it to 100, it works well.

(http://ifh.wo.tc/g/C5HHH.png)


Thanks for contributing :)