www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: kakashi on June 08, 2009, 06:30:41 pm

Title: Resize FrameBuffer or paint it in the whole canvas.
Post by: kakashi on June 08, 2009, 06:30:41 pm
Hi,

How can I resize FrameBuffer when the canvas get resized (or emulate this painting the Frame buffer in the whole resized canvas)??,

Im creating a thread per created panel to update the objects, I was thinking about:
1-Remove the canvas from the panel
2-Destroy the FrameBuffer,
3-Recreate the Frame buffer with the new size
4-add the canvas again to the panel.

I dont know how to paint it in the whole resized canvas, it is possible??

Here is the main parts of my Panel code:



Code: [Select]

public class PointCloudPanel extends javax.swing.JPanel {

    public void initCanvas()
    {
        world = new World();
        world.setAmbientLight(255, 255, 0);

TextureManager.getInstance().addTexture("box", new Texture("c:\\1191.jpg"));
        box = Primitives.getBox(13f, 2f);
        box.setTexture("box");
        box.setEnvmapped(Object3D.ENVMAP_ENABLED);
        box.build();
        world.addObject(box);
        world.getCamera().setPosition(50,50, 50);
        world.getCamera().lookAt(box.getTransformedCenter());

        this.setSize(320, 240);
        buffer = new FrameBuffer(this.getWidth(), this.getHeight(), FrameBuffer.SAMPLINGMODE_GL_AA_4X);
        canvas = buffer.enableGLCanvasRenderer();
        buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
        this.add(canvas);

        IPaintListener listener = new IPaintListener() {
            public void finishedPainting() {}
        };


        buffer.setPaintListener(listener);
        canvas.addComponentListener(new ComponentAdapter() {
            @Override
            public void componentResized(ComponentEvent ce) {
                System.out.println("RESIZED");
            }
        });


        Thread thread = new LoopThread(this);
        thread.start();

       
    }

    public PointCloudPanel() {
        initComponents();
        initCanvas();     
    }

    class LoopThread extends Thread {


        LoopThread(PointCloudPanel jp) {
        }

        @Override
        public void run() {


            while (true) {
                box.rotateY(0.01f);
                world.getCamera().lookAt(box.getTransformedCenter());
                buffer.clear(java.awt.Color.GRAY);
                world.renderScene(buffer);
                world.draw(buffer);
                buffer.update();
                buffer.displayGLOnly();
                canvas.repaint();
                try {
                    LoopThread.sleep(10);
                    increment += 1;
                } catch (InterruptedException ex) {
                }
            }
        }
    }
           
    private World world;
    private FrameBuffer buffer;
    private Object3D box;
    private Canvas canvas;
    private float increment = 0;
}






Let me know if you know another method please.

Thanks for any help!
Title: Re: Resize FrameBuffer or paint it in the whole canvas.
Post by: JavaMan on June 08, 2009, 10:46:32 pm
I see two other ways to do this.

One way would be to get the Image from FrameBuffer.getOutputBuffer();
You could then get the graphics context of whatever component you want to draw onto and call component.drawImage(image,...,...,componet.width,component.height,...);

Also, you could use FrameBuffer.display(Graphics) and draw onto an image. You could then draw this image like I said above.
component.drawImage(image,...,...,componet.width,component.height,...);

EDIT: Oops sorry about that. What I suggest would only work with the Software Renderer enabled. I must have misread something on the forums somewhere else.
Title: Re: Resize FrameBuffer or paint it in the whole canvas.
Post by: EgonOlsen on June 09, 2009, 06:52:32 am
That won't work, because he's using a GL renderer in that canvas. That aside, i don't get the question. Your bullets points 1-4 sound reasonable to me. But what do you mean by "paint it in the whole canvas"? Rescale it during display? Is that an addition to your bullet points or another possible solution to handle the resize problem?
Title: Re: Resize FrameBuffer or paint it in the whole canvas.
Post by: kakashi on June 15, 2009, 07:52:40 pm
the bullets points 1-4 was an idea of how to do it, but it doesnt work  :'( .

By "paint it in the whole canvas" I mean for example, when you create a 320x240 Framebuffer then a canvas, then attach it to a Panel In a window (every one with 320x240) and then you resize the canvas, panel, window etc to 640x480, everything is resized but the 3D renders in a 320x240 section inside the canvas that is 640x480, so I need to rescale the rendered image I guest, but I dont know how to do It, any idea????
Title: Re: Resize FrameBuffer or paint it in the whole canvas.
Post by: EgonOlsen on June 15, 2009, 08:13:29 pm
As far as i can see at first glance, 1-4 should do the trick. What exactly doesn't work? Do you have a small, stand alone test case for this?
Title: Re: Resize FrameBuffer or paint it in the whole canvas.
Post by: paulscode on June 15, 2009, 11:40:02 pm
1-Remove the canvas from the panel
2-Destroy the FrameBuffer,
3-Recreate the Frame buffer with the new size
4-add the canvas again to the panel.
You are probably already doing this, but just to be sure, did you also recreate the canvas after recreating the frame buffer?  Something like this:
Code: [Select]
buffer.dispose();
this.remove( canvas );
this.validate();

buffer = new FrameBuffer( this.getWidth(), this.getHeight(), FrameBuffer.SAMPLINGMODE_GL_AA_4X );
buffer.disableRenderer( IRenderer.RENDERER_SOFTWARE );
canvas = buffer.enableGLCanvasRenderer();

this.add( canvas, BorderLayout.CENTER );
this.validate();
canvas.setVisible( true );
canvas.validate();