NEWT, initial black frame

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

NEWT, initial black frame

Andre
This post was updated on .
Hi again,

a question to the attached source code: Is there a way to get rid of the flickering and black frame of the start-up phase of NEWT?

I took a screenshot and used it immediately as texture to generate a Magnifier program later for windows that looks like the magnifying feature of Mac.

But in the beginning i have got a black frame before newt draws the texture.
Any way around it?

Take care: to exit the source code just press ESC.

PS: i tried that without NEWT, like with BufferedImage and offscreen buffer, and it works instantly and seamless, no black frame. But Java's native interpolation looks too bad compared to OpenGL during the scale 1.0f to 1.5f


EXAMPLE CODE:

import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;

import com.jogamp.newt.event.KeyAdapter;
import com.jogamp.newt.event.KeyEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
import com.jogamp.opengl.util.FPSAnimator;
import com.jogamp.opengl.util.texture.Texture;
import com.jogamp.opengl.util.texture.TextureData;
import com.jogamp.opengl.util.texture.awt.AWTTextureIO;

public class Example_Newt_Black_Frame extends JFrame implements GLEventListener {

        public static void main(String[] args) throws AWTException {
                System.setProperty("sun.java2d.uiScale", "1");
                new Example_Newt_Black_Frame();
        }

        private Rectangle screen;
        private BufferedImage image;
        private Texture texture;

        public Example_Newt_Black_Frame() throws AWTException {
                this.screen = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
                this.image = new Robot().createScreenCapture(this.screen);
                GLWindow window = GLWindow.create(new GLCapabilities(GLProfile.getDefault()));
                window.addKeyListener(new KeyAdapter() {
                        @Override
                        public void keyPressed(KeyEvent e) {
                                if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                                        System.exit(0);

                        }
                });
                window.addGLEventListener(this);
                window.setFullscreen(true);
                window.setVisible(true);
                FPSAnimator animator = new FPSAnimator(window, 60, false);
                animator.start();
        }

        @Override
        public void init(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();
                TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), image, true);
                texture = new Texture(gl, data);
                data.flush();
                this.image = null;
        }

        @Override
        public void display(GLAutoDrawable drawable) {
                GL2 gl = drawable.getGL().getGL2();
                gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
                this.texture.enable(gl);
                this.texture.bind(gl);
                gl.glBegin(GL2.GL_TRIANGLE_STRIP);
                gl.glTexCoord2f(0, 0);
                gl.glVertex2d(0, 0);
                gl.glTexCoord2f(1, 0);
                gl.glVertex2d(this.screen.getWidth(), 0);
                gl.glTexCoord2f(0, 1);
                gl.glVertex2d(0, this.screen.getHeight());
                gl.glTexCoord2f(1, 1);
                gl.glVertex2d(this.screen.getWidth(), this.screen.getHeight());
                gl.glEnd();
                this.texture.disable(gl);
        }

        @Override
        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
                GL2 gl = drawable.getGL().getGL2();
                gl.glViewport(0, 0, width, height);
                gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
                gl.glLoadIdentity();
                gl.glOrtho(0, width, height, 0, -10, 10);
        }

        @Override
        public void dispose(GLAutoDrawable drawable) {
        }
}
I am a Robot
Reply | Threaded
Open this post in threaded view
|

Re: NEWT, initial black frame

Andre
Solution: I need to rearrange the clear buffer and initial drawing steps so that the first frame is already drawn as a prepared graphic.
I am a Robot