Offscreen buffering and antialiasing not working?

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

Offscreen buffering and antialiasing not working?

Andre
This post was updated on .
Hi

as the title says i am using the offscreen capability of NEWT
but as i turned samplebuffers on
the image is gone.

I am more or less setting it up like below
and it works like a charm to render textures and stuff.
Forbidden? Non-possible?


public class GLOffscreen {

        private GLProfile profile;
        private GLCapabilities capabilities;
        private GLDrawableFactory factory;
        private GLAutoDrawable drawable;
        private GLOffscreenListener listener;
        private AWTGLReadBufferUtil glReadBufferUtil;
        private GL2 gl;

        public GLOffscreen(int width, int height) {
                this.profile = GLProfile.getDefault();
                this.capabilities = new GLCapabilities(profile);
                this.capabilities.setHardwareAccelerated(true);
                this.capabilities.setDoubleBuffered(false);
                this.capabilities.setAlphaBits(8);
                this.capabilities.setOnscreen(false);
// this.capabilities.setSampleBuffers(true);
// this.capabilities.setNumSamples(4);
                this.factory = GLDrawableFactory.getFactory(profile);
                this.drawable = factory.createOffscreenAutoDrawable(null, capabilities, null, width, height);
                this.drawable.display();
                this.drawable.getContext().makeCurrent();
                this.gl = drawable.getGL().getGL2();
                this.gl.glViewport(0, 0, width, height);
                this.gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
                this.gl.glLoadIdentity();
                this.gl.glOrtho(0d, width, height, 0d, -1d, 1d);
                this.gl.glDisable(GL2.GL_DEPTH_TEST);
                this.glReadBufferUtil = new AWTGLReadBufferUtil(gl.getGL2().getGLProfile(), true);
        }

        public void addListener(GLOffscreenListener listener) {
                this.listener = listener;
        }

        public void display() {
                this.listener.render(this.drawable);
        }

        public BufferedImage getBufferedImage(int x, int y, int width, int height) {
                return this.glReadBufferUtil.readPixelsToBufferedImage(this.gl, x, y, width, height, true);
        }

        public void clear() {
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
        }

}
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

gouessej
Administrator
Hello

By the way, avoid storing the GL instances into fields, it should be used only locally.

Offscreen buffering and antialiasing work. Maybe the there is no drawable that matches the requested capabilities in your case. I advise you to look at our unit tests and to try different combinations, for example with setDoubleBuffered(true) and/or setHardwareAccelerated(false).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

gouessej
Administrator
In reply to this post by Andre
Which version of JOGL do you use?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Sven Gothel
Administrator
In reply to this post by Andre
Hi Andre, please follow bug reporting as described here and attach the files.
<https://forum.jogamp.org/How-do-I-use-stencil-textures-for-outlining-shapes-tp4042652p4042653.html>

Thank you.
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Andre
@gouessej:
GL ... i know, i dont know why thou. Just testing before beginning to use it.
Should i better call "  drawable.getGL().getGL2(); " again and again? Newbie.
2.4.0

@Sven:
is it a bug ? (kaefer)
i am confused about what to do next and where.
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Andre
This post was updated on .
In reply to this post by gouessej
@gouessej:
Tried much, did not see it yet. Normally without offscreen it works.
Below, better? see GL2. isnt it save if you store it into a field? Heard of it but no reason.
What or where are the Unit tests?

THX



import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLDrawableFactory;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.util.awt.AWTGLReadBufferUtil;

import java.awt.image.BufferedImage;

public class GLOffscreen {

        private GLProfile profile;
        private GLCapabilities capabilities;
        private GLDrawableFactory factory;
        private GLAutoDrawable drawable;
        private GLOffscreenListener listener;
        private AWTGLReadBufferUtil glReadBufferUtil;

        public GLOffscreen(int width, int height) {
                this.profile = GLProfile.getDefault();
                this.capabilities = new GLCapabilities(profile);
                this.capabilities.setHardwareAccelerated(true);
                this.capabilities.setDoubleBuffered(false);
                this.capabilities.setAlphaBits(8);
                this.capabilities.setOnscreen(false);
// this.capabilities.setSampleBuffers(true);
// this.capabilities.setNumSamples(4);
                this.factory = GLDrawableFactory.getFactory(profile);
                this.drawable = factory.createOffscreenAutoDrawable(null, capabilities, null, width, height);
                this.drawable.display();
                this.drawable.getContext().makeCurrent();
                this.glReadBufferUtil = new AWTGLReadBufferUtil(this.profile, true);
        }

        public void addListener(GLOffscreenListener listener) {
                this.listener = listener;
                this.listener.init(this.drawable);
        }

        public void display() {
                this.listener.display(this.drawable);
        }

        public BufferedImage getBufferedImage(int x, int y, int width, int height) {
                GL2 gl = drawable.getGL().getGL2();
                return this.glReadBufferUtil.readPixelsToBufferedImage(gl, x, y, width, height, true);
        }

        public void clear() {
                GL2 gl = drawable.getGL().getGL2();
                gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
        }

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import com.jogamp.opengl.GLAutoDrawable;

public interface GLOffscreenListener {

        public abstract void init(GLAutoDrawable drawable);

        public abstract void display(GLAutoDrawable drawable);

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;

import kito.gl.GLOffscreen;
import kito.gl.GLOffscreenListener;
import kito.gl.GLUtil;
import kito.util.Check;

public class Example_Jogl_Offscreen_Rendering implements GLOffscreenListener {

        static int size = 1024;
        static GLOffscreen offscreen;

        public static void main(String[] args) throws Exception {
                offscreen = new GLOffscreen(size, size);
                offscreen.addListener(new Example_Jogl_Offscreen_Rendering());
                offscreen.display();
        }

        @Override
        public void init(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();
                gl.glViewport(0, 0, size, size);
                gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
                gl.glLoadIdentity();
                gl.glOrtho(0d, size, size, 0d, -1d, 1d);
                gl.glDisable(GL2.GL_DEPTH_TEST);
        }

        @Override
        public void display(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();
                GLUtil.drawOval2(gl, size / 2f, size / 2f, size / 25, .1f, 64, 1f, 1f, 0f);
                new Check(offscreen.getBufferedImage(0, 0, size, size), null);
        }
}
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

gouessej
Administrator
In reply to this post by Andre
When you store the GL instance into a field, you might use it either on the wrong thread or on the thread on which you created it but not when its OpenGL context is current or when it has become invalid. You can store it into a local variable and use it preferably in a GLEventListener. If you don't follow my advice, you will just go into troubles one day whereas it can be avoided.

We are all newbies one day. I was a newbie when I began learning DOS in 1989, I was a newbie again when I started using JOGL in about 2006, it's ok.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Sven Gothel
Administrator
   this.capabilities.setAlphaBits(8);
   this.capabilities.setOnscreen(false);
// this.capabilities.setSampleBuffers(true);
// this.capabilities.setNumSamples(4);
Then perhaps try
  this.capabilities.setAlphaBits(1); // <- the biggest will be used while having sample buffers >= 4
  this.capabilities.setOnscreen(false);
  this.capabilities.setSampleBuffers(true);
this.capabilities.setNumSamples(4);
In both cases, hmm .. try the debug option and pipe all into a file and attach,
I referenced a late post above ;-)

Then the following will also list all available formats/caps:
java -cp jogamp-fat.jar com.jogamp.newt.opengl.GLWindow

# with piped out file
java -cp jogamp-fat.jar com.jogamp.newt.opengl.GLWindow 2>&1 | tee test.log
The following will add debug code (also about chosen caps):
java -Djogl.debug=all -cp jogamp-fat.jar com.jogamp.newt.opengl.GLWindow

# with piped out file
java -Djogl.debug=all -cp jogamp-fat.jar com.jogamp.newt.opengl.GLWindow 2>&1 | tee test_dbg.log
.. hope that may help a little
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Sven Gothel
Administrator
.. and if - for some reason the used DefaultGLCapabilityChoser and/or hence the GLX/X11 or WGL/Win32 default capsability picker is not good enough (or buggy) .. you can use your own:

Example of a GLCapabilitiesChooser impl is: NonFSAAGLCapsChooser <https://jogamp.org/cgit/jogl.git/tree/src/jogl/classes/com/jogamp/opengl/util/caps/NonFSAAGLCapsChooser.java>.

Example usage in UISceneDemo20 <https://jogamp.org/cgit/jogl.git/tree/src/demos/com/jogamp/opengl/demos/graph/ui/UISceneDemo20.java#n167>.

Hope that helps...
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Andre
THAAAAANKS.... ill try that and be back.
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: Offscreen buffering and antialiasing not working?

Andre
This post was updated on .
In the long term, I took a different approach by using Frame Buffer Objects (FBO) and pseudo-antialiasing.
Multisampling on a slow machine isn’t working for me right now.

Here a picture with gradient antialiasing.
Works, enough.

I am a Robot