Offscreen Rendering with GLCanvas which wasn't created with this capability ?!

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Offscreen Rendering with GLCanvas which wasn't created with this capability ?!

Nosezeichen
Hi,

I'm struggling with a third Party JOGL-Application wich I want to integrate into my own jMonkeyEngine application.

Basically I want to enable offscreen-rendering with a GLCanvas wich was created without this capability. Is it somehow possible to change capabilities after creating a Canvas ? Or use some other hackish methods to render it anyhow ?

I had to implement an abstract method of the 3rd-Party app:

public void embedInContainer(Component jacanvas) {
        // jacanvas is in fact an Object of type javax.media.opengl.awt.GLCanvas

        /* Initialization */
        // create JPanel and configure it
        javax.swing.JPanel panel;
        panel = new JPanel(new BorderLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
        panel.setPreferredSize(size);
        panel.setMinimumSize(size);
        panel.setMaximumSize(size);
        panel.setSize(size);
        panel.setBounds(0, 0, size.width, size.height);
        panel.setBackground(Color.red);
        // Add the GLCanvas which is in the comp variable to the JPanel
        panel.add(comp, BorderLayout.CENTER);
        panel.setVisible(true);

        // create JFrame and configure it
        javax.swing.JFrame frame;
        frame = new JFrame();
        frame.setBackground(Color.WHITE);
        frame.setUndecorated(true);
        frame.setPreferredSize(size);
        frame.setMinimumSize(size);
        frame.setMaximumSize(size);
        frame.setSize(size);
        frame.setBounds(0, 0, size.width, size.height);
        // Add the panel to the frame
        frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true); // I can see the ouptut and can copy it to my buffer via glReadPixels
       
        frame.setVisible(false); // I can't see output and buffer holds a black image (like I expected, because it's not an offscreen renderable)
}

When putting the GLCanvas to a visible frame the output of the 3rd-Party app is shown. When setting the frame invisible the GLCanvas doesnt become rendered at all (reading the rendered output into my buffer with glReadPixels delivers a black image).

The jframe and jpanel stuff is just to see if it works at all. I dont want to use them. I want to put the output of the 3rd party jogl app into a buffer so that i can use it as a texture later on.

I've allready posted my Problem in the jme-forum but no one seems to can help me.
Here is the Post with a code example and a description: http://hub.jmonkeyengine.org/forum/topic/how-to-render-a-glcanvas-inside-jme3/

Thank you!
Nosezeichen


Reply | Threaded
Open this post in threaded view
|

Re: Offscreen Rendering with GLCanvas which wasn't created with this capability ?!

gouessej
Administrator
Hi

I don't think that you can enable offscreen rendering with a GLCanvas after its creation, maybe Sven can confirm. setShallUseOffscreenLayer(true) must be called very early.

This forum is the best place to ask some questions about JOGL. Do you use the JOGL backend of JMonkeyEngine 3?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen Rendering with GLCanvas which wasn't created with this capability ?!

gouessej
Administrator
In reply to this post by Nosezeichen
Hi

You can put the GLCanvas into a JPanel and call JPanel.paint(BufferedImage.createGraphics()). Override the method paintComponent(Graphics) of the JPanel so that it calls GLAutoDrawable.display(). It's hacky but it might work. You can use the BufferedImage to retrieve the rendered "data" and display them where you want. Good luck.
Julien Gouesse | Personal blog | Website