Login  Register

Offscreen buffering and antialiasing not working?

Posted by Andre on May 27, 2023; 3:01pm
URL: https://forum.jogamp.org/Offscreen-buffering-and-antialiasing-not-working-tp4042649.html

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