Difference GLJpanel et GLCanvas ?
Bonjour,
Je m'interesse depuis peu à OpenGL et je me fais la main sur différents tutos en java ( jogl ). Je suis tombé sur 2 cas d'initialisation :
- avec GLJPanel
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
public class XXX extends JFrame implements GLEventListener{
protected GLJPanel GLJPanel1 = null;
public static void main(String[] args) {
new XXX();
}
public XXX() {
super("XXX");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GLCapabilities GLCapabilities1 = new GLCapabilities();
GLCapabilities1.setHardwareAccelerated(true);
GLCapabilities1.setDoubleBuffered(true);
GLCapabilities1.setDepthBits(8);
// to show we can mix AWT and opengl rendering
GLJPanel1 = new GLJPanel(GLCapabilities1) {
public void paint (Graphics Graphics_Arg){
super.paint(Graphics_Arg);
}
};
GLJPanel1.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
...
GLJPanel1.repaint();
}
});
GLJPanel1.setFocusable(true);
GLJPanel1.setRequestFocusEnabled(true);
Thread Thread1 = new Thread(){
public void run(){
while (true) {
Thread.currentThread().yield();
try {
Thread.currentThread().sleep(10);
} catch (InterruptedException e) {}
}
}
};
Thread1.start();
GLJPanel1.addGLEventListener(this);
setSize(512, 512);
setVisible(true);
GLJPanel1.requestFocus();
}// Constructor |
- avec GLCanvas
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
class Main implements GLEventListener, MouseListener, MouseMotionListener, KeyListener {
private GLU glu = new GLU();
public static void main(String[] args) {
Frame frame = new Frame("Test");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new Main());
frame.add(canvas);
frame.setSize(640, 480);
animator = new Animator(canvas);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
frame.setVisible(true);
animator.start();
} |
Hormis la mise en oeuvre qui est différente, je ne vois pas pourquoi choisir l'un plutôt que l'autre ?
Merci de vos lumières
Laurent