in my program whole scene is renderd using SimpleCanvasImpl (based moste of the code on RenParticleEditor). I need to apply a BloomRenderPass to one of nodes.
To do this I modified the class that extends SimpleCanvasImpl in the following way:
The effects are really bizarre - the sphere and it's bloomed representation are displaced. The more I zoom towards the sphere the closer bloomed representation is.
What am I doing wrong?
Btw: in the simpleSetup I attach lots of other nodes that should not be affected by bloom effect. Should I add rootNode to the RenderPass or should I add only the node that has to be affected by bloom?
And if I add rootNode to the RenderPass will it be rendered twice - SimpleCanvasImpl.doRender looks like this:
public void doRender() {
renderer.clearBuffers();
renderer.draw(rootNode);
simpleRender();
renderer.displayBackBuffer();
}
Perhaps all the fuss is because of my misunderstanding how RenderPasses works.
For your convenience I removed all the unnecessary parts of the code and left only things necessary to reproduce this behaviour. As I wrote I based my implementation on RenParticleEditor so most of the code is just a “copy/paste”. What was changed in this demo class is the Sphere in simpleSetup and stuff with BloomRenderPass in SimpleCanvasImpl.
not sure but DIsplaySystem.getDisplaySystem.getWidth() ( used by the bloom pass to get the "screen" size) returns width 640 whereas DIsplaySystem.getDisplaySystem.getRenderer().getWidth() returns 485 …
Indeed - this is it - if I resize the window I can see that the bloom visualisation is moving - eventually when I make the window smaller the visualisation of the sphere starts to overlap the bloom visualisation. Kine thank you very much!
But now the question is how to solve this problem :?
The mechanism used in RenParticleEditor to update canvas size looks like this:
// add a listener... if window is resized, we can do something about it.
glCanvas.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent ce) {
doResize();
}
});
Where the impl is the instance of the class that extends the SimpleCanvasImpl. I don't know if it's worth pasting jMe sourcecode but JMECanvasImplementor.resizeCanvas looks like this:
public void resizeCanvas(int newWidth, int newHeight) {
final int fWidth = newWidth <= 0 ? 1 : newWidth;
final int fHeight = newHeight <= 0 ? 1 : newHeight;
Callable<?> exe = new Callable<Object>() {
public Object call() {
if (renderer != null) {
renderer.reinit(fWidth, fHeight);
height = fHeight;
width = fWidth;
}
return null;
}
};
GameTaskQueueManager.getManager().getQueue(GameTaskQueue.RENDER).enqueue(exe);
}
So the question what do I have to do update DisplaySystem width and height properly?
The best way to handle this is probably to remove the calls getWidth and getHeight from DisplaySystem as they don't really belong there. I guess a hack around this issue would be to update the DisplaySystem width/height when the reinit method is called on Renderer.
/**
* ComponentListener for use with Applets or Canvas.<br>
* Listens for resize events from an awt Component and reinitializes the Renderer.
*/
public class ComponentResizeListener implements ComponentListener {
private Component component;
public ComponentResizeListener(Component component) {
this.component = component;
}
public void componentHidden(ComponentEvent ce) {
}
public void componentMoved(ComponentEvent ce) {
}
/**
* Reinitializes the renderer based on the applets new size.<br>
* Sets the new width and height in the displaysystem.
*/
public void componentResized(final ComponentEvent ce) {
Callable<?> exe = new Callable<Object>() {
int w = component.getWidth();
int h = component.getHeight();