Re: Jogl/Jogamp on Java 9
Posted by Andy Skinner on Jun 14, 2018; 8:03pm
URL: https://forum.jogamp.org/Jogl-Jogamp-on-Java-9-tp4038012p4038934.html
I wrote a simple program that creates a GLJPanel and prints out the surface scale, surface size, and component size.
On Mac with Retina, I get surface scale of 2, and surface size is twice the component size. (getSurfaceWidth vs getWidth)
On Windows running with Java 10, I still get surface scale of 1 and surface size the same as component size.
My understanding of the Java 9 Windows high DPI change was that Windows would work more like Mac.
My Windows display is set to magnify by 150%. Should I have seen something like what I saw on mac?
I don't see an attach button, so I'll just give you the code.
thanks
andy
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.*;
public class winHiDPI extends JFrame implements GLEventListener {
GLJPanel fCanvas;
winHiDPI() {
setSize(400,300);
GLCapabilities caps = new GLCapabilities(null);
fCanvas = new GLJPanel(caps);
fCanvas.addGLEventListener(this);
fCanvas.setAutoSwapBufferMode(true);
getContentPane().add(fCanvas, BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
getContentPane().remove(fCanvas);
}
});
}
@Override
public void init(GLAutoDrawable d) {
final GL2 gl = d.getGL().getGL2();
gl.glClearColor(1.0f, 1.0f, 0.5f, 1.0f);
float[] scales = new float[2];
fCanvas.getCurrentSurfaceScale(scales);
System.out.println("surface scale: " + scales[0] + " " + scales[1]);
System.out.println("surface size: " +
fCanvas.getSurfaceWidth() + " " + fCanvas.getSurfaceHeight());
System.out.println("Component size: " +
fCanvas.getWidth() + " " + fCanvas.getHeight());
}
@Override
public void display(GLAutoDrawable d) {
final GL2 gl = d.getGL().getGL2();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glVertex3f(-0.5f, -0.5f, 0.0f);
gl.glVertex3f( 0.5f, -0.5f, 0.0f);
gl.glVertex3f( 0.0f, 0.5f, 0.0f);
gl.glEnd();
}
@Override
public void reshape(GLAutoDrawable d,int x,int y,int w,int h) {
}
@Override
public void dispose(GLAutoDrawable d) {
}
public static void main(String[] args) {
final winHiDPI frame = new winHiDPI();
frame.setVisible(true);
}
}