Dear All,
Could anybody help me how to set the cursor in jogl2 when using native window?
Thanks in advance!
Dear All,
Could anybody help me how to set the cursor in jogl2 when using native window?
Thanks in advance!
sry for my ignorance but how native windows can be used ?
See demos.GLInfo code from Jogl2.0 demo src.
I think whenever it is possible Jogl2 will use the new native window automatically. But I know it not exactly, because with Jogl2 I have only experience on the local PC.
The cursor changing seems to work in the normal awt way.
This sample works for me:
package test;
import java.awt.Frame;
import java.awt.Point;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.awt.GLCanvas;
import com.sun.opengl.util.Animator;
public class Test implements GLEventListener {
public static void main(final String[] args) {
final Test test = new Test();
final Frame frame = new Frame();
final GLCanvas canvas = new GLCanvas();
final Animator animator = new Animator(canvas);
// cursor changing
try {
final BufferedImage cursorImg = ImageIO.read(test.getClass().getClassLoader().getResourceAsStream("fancy/cursor.png"));
canvas.setCursor(canvas.getToolkit().createCustomCursor(cursorImg, new Point(), ""));
} catch (final IOException e) {
e.printStackTrace();
}
canvas.addGLEventListener(test);
frame.add(canvas);
frame.setSize(300, 300);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
frame.setVisible(true);
animator.start();
}
@Override
public void init(final GLAutoDrawable drawable) {
System.out.println(drawable);
//results in: AWT-GLCanvas[ class javax.media.nativewindow.awt.AWTGraphicsConfiguration...
}
@Override
public void display(final GLAutoDrawable drawable) {}
@Override
public void dispose(final GLAutoDrawable drawable) {}
@Override
public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {}
}
i know i have been using JFrame-based rendering for years, but native windows would give much better performance, that is why i would like to use it…
Thanks anyway!
If you guys have some code for ‘setCursor’ then feel free to add it to NEWT’s Window class - would be awesome !
For the native X11, MacOSX, Windows and AWT … implementation.
Volunteers ?
Send me your git branch location