Re: Mac Canvas3D location bug
Posted by
jimthev on
Oct 23, 2013; 9:15pm
URL: https://forum.jogamp.org/Mac-Canvas3D-location-bug-tp4030052p4030354.html
Using the 10/19/13 release of jogl: on OSX, using setBounds on GLCanvas only seems to set the origin initially. Subsequent setBounds calls only set the height/width and leave the lower left location of the window the same.
I modified my test to animate moving the canvas across the screen while changing its size. The window should move to the right, getting shorter and wider as it goes. It works for the latest jre in windows (7u45) but fails under the 1.7.0_45-b18 in Safari on OSX 10.8.5. It does work correctly if you run it on the command line in OSX though.
package test;
import java.applet.Applet;
import java.awt.Color;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JoglCanvasTest extends Applet implements GLEventListener {
public JoglCanvasTest() {
}
public static JFrame frame;
public static JPanel appletHolder;
public static boolean isApplet = true;
public static GLCanvas canvas;
public static int canvasXLocation = 50;
static public void main(String args[]) {
Applet myApplet = null;
isApplet = false;
myApplet = new JoglCanvasTest();
appletStarter(myApplet, "JoglCanvasTest", 800, 600);
}
static public void appletStarter(final Applet des, String frameName, int width, int height) {
appletHolder = new JPanel();
if (frame != null) {
frame.dispose();
frame = null;
}
frame = new JFrame(frameName);
frame.setVisible(false);
frame.getContentPane().add(appletHolder);
appletHolder.setLayout(null);
des.setBounds(0, 0, width, height);
appletHolder.add(des);
frame.setVisible(true);
int frameBorderSize = appletHolder.getLocationOnScreen().x - frame.getLocationOnScreen().x;
int titleBarHeight = appletHolder.getLocationOnScreen().y - frame.getLocationOnScreen().y;
int frameWidth = width + 2 * frameBorderSize;
int frameHeight = height + titleBarHeight + frameBorderSize;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(frameWidth, frameHeight);
frame.setVisible(true);
des.init();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
public void init() {
initOpenGLAWT();
Runnable r = new Runnable() {
public void run() {
try {
int loop = 0;
while (loop < 3) {
Thread.sleep(1000);
canvasXLocation += 50;
if (canvasXLocation > 300) {
canvasXLocation = 0;
loop++;
}
canvas.setBounds(canvasXLocation, 50, 200 + canvasXLocation, 450 - canvasXLocation);
}
} catch (Exception e) {
}
}
};
new Thread(r).start();
}
public void initOpenGLAWT() {
setBackground(Color.gray);
setLayout(null);
GLProfile glp = GLProfile.getDefault();
GLCapabilities caps = new GLCapabilities(glp);
canvas = new GLCanvas((GLCapabilitiesImmutable) caps);
canvas.setBounds(50, 50, 200, 450);
canvas.addGLEventListener(this);
add(canvas);
}
public void init(GLAutoDrawable gLAutoDrawable) {
GL gl = gLAutoDrawable.getGL();
gl.glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gLAutoDrawable.swapBuffers();
}
public void dispose(GLAutoDrawable glad) {
}
public void display(GLAutoDrawable glad) {
}
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
}