Skip to main content

Render scene offscreen

2 replies [Last post]
tml
Offline
Joined: 2003-06-09
Points: 0

Hi,

I want to render scene into offscreen buffer. Actualy I am trying to use FlipBufferStrategy, so I need to render scene into Graphics object that I get from BufferStrategy.getDrawGraphics() .
Can please someone point me how to do it ?

Thanks,

Tibor

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jantaubert
Offline
Joined: 2007-12-12
Points: 0

This should do the trick. Pass your Graphics object to the paint method.

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Rectangle;

import com.sun.scenario.scenegraph.JSGPanel;

@SuppressWarnings("serial")
public class OffscreenJSGPanel extends JSGPanel {

/**
* Paint the component.
*
* @param g
* The graphics context onto which the component is to be
* painted.
* @see java.awt.Component#paint(java.awt.Graphics)
*/
public void paint(Graphics g) {
// As the panel doesn't belong to a window, we need to explicitly layout
// the components
doLayout();

Graphics gr = g.create();

// Print the component
printComponent(gr);

// ... any border
printBorder(gr);

// ... and all of the children.
for (int c = 0; c < getComponentCount(); c++) {
Component comp = getComponent(c);
Rectangle cr = comp.getBounds();

Graphics cg = gr.create(cr.x, cr.y, cr.width, cr.height);
comp.printAll(cg);
}
}

/**
* Is this component showing.
*
* @return This is always true so that the panel will be
* rendered.
* @see java.awt.Component#isShowing()
*/
public boolean isShowing() {
return true;
}

}

tml
Offline
Joined: 2003-06-09
Points: 0

thanks Jan, it works !