Embedding a JME Canvas to a Swing application works fine for me… until I want to use my own extended LwjglRenderer.
In full screen apps I overwrote the renderer in
[java]
public void simpleInitApp() {
…
renderer = new MyRenderer();
…
}
[/java]
I was actually surprised that it worked, but it doesn’t anymore when it is put into a panel (just a black screen, no errors).
My question is: How do I initialize my own renderer in a Swing application?
You don’t want to initialize or extend a renderer… A renderer is what initializes the Canvas… Extending a renderer makes no sense at all, you would have to write a new renderer for anther platform. What are you trying to do anyway? The render loop is already started when you are in simpleInitApp(). If you want to change how things work in the renderer you will have to change and compile jME3 yourself. But given these basic misunderstandings I doubt you will get very happy trying to pursue that path ^^
Extending the Renderer was the only option (also according Momoko_Fan) to get access to LwjglRenderer.readFrameBuffer() with the right format an type.
See thread: http://hub.jmonkeyengine.org/groups/graphics/forum/topic/jme3-zbuffer/
Creating a new renderer is indeed an ugly work-around that fails horribly with the Swing example.
Adding a generalized method with format and type parameters in JME3’s LwjglRenderer would be cleanest. Then there are also no problems like the one above.
But indeed, Normen, I don’t feel like deviating and compile my own version of JME3. You or any of the other JME3 developers in favor to change LwjglRenderer to:
[java]
// Color image
public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
readFrameBuffer(fb, byteBuf, format, GL_BGRA, GL_UNSIGNED_BYTE);
}
// General wrapper for glReadPixels()
public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf, int format, int type) {
if (fb != null) {
RenderBuffer rb = fb.getColorBuffer();
if (rb == null) {
throw new IllegalArgumentException(“Specified framebuffer”
- " does not have a colorbuffer");
}
setFrameBuffer(fb);
if (context.boundReadBuf != rb.getSlot()) {
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
context.boundReadBuf = rb.getSlot();
}
} else {
setFrameBuffer(null);
}
glReadPixels(vpX, vpY, vpW, vpH, format, type, byteBuf);
}
[/java]
That would also allow
[java]
// Depth values
public void readDepthBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
readFrameBuffer(fb, byteBuf, format, GL_DEPTH_COMPONENT, GL_FLOAT);
}
[/java]
or a call outside LwjglRenderer.
Momoko_fan already quickly mentioned:“We should really make this built-in functionality …”.
Can I contribute this change myself?