Author Topic: Print framebuffer to image and append texture  (Read 2283 times)

Offline ppparkje

  • byte
  • *
  • Posts: 9
    • View Profile
Print framebuffer to image and append texture
« 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).



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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12297
    • View Profile
    • http://www.jpct.net
Re: Print framebuffer to image and append texture
« Reply #1 on: August 18, 2012, 09:49:33 pm »
Try to set Config.useFramebufferWithAlpha=true; before creating the FrameBuffer and see if that helps.

Offline ppparkje

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Print framebuffer to image and append texture
« Reply #2 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?

Offline ppparkje

  • byte
  • *
  • Posts: 9
    • View Profile
Re: Print framebuffer to image and append texture
« Reply #3 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.




Thanks for contributing :)
« Last Edit: August 20, 2012, 07:39:45 am by ppparkje »