Take a java.awt.Window, put a java.awt.Canvas in it and use Display.setParent(...) to bind your surface to the canvas.
I've returned to this project, and made it work. But now I want to know how does resizing of the window work (Display.getWidth or JFrame.getWidth())? If I render something on screen with opengl (I use Display.getWidth/2 to render 2D in center) and then resize this screen everything moves out of place (aspect ratio messes up, before I used Display.wasResized() to renew ratio on gluPerspective). I tryed to use Frame.getWidth() and getHeight() but I get same result. I want to know how are display and jframe connected exactly.
sry for my typing, i need to get some sleep.
parent code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| Canvas = new Canvas(); Frame = new JFrame("sup");
Frame.setSize(1280, 720); Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setBackground(Color.BLACK); Canvas.setBackground(Color.BLACK); Frame.getContentPane().add(Canvas); Frame.setLocationRelativeTo(null); Frame.setVisible(true); try { Display.setVSyncEnabled(true); Display.setParent(Canvas); Display.create(); } catch (Exception e) { e.printStackTrace(); Display.destroy(); System.exit(0); } |