The main problem is inside the AWT Canvas in order to get a drawable and a context
he uses these two lines but it seems they are deprecated.
http://download.java.net/media/jogl/jogl-2.x-docs-next/// get a rendering surface and a context for this canvas
drawable = GLDrawableFactory.getFactory().getGLDrawable(this, caps, null);
context = drawable.createContext(null);
ANY HELP?
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat;
import javax.media.opengl.*;
public class CubeGL extends JFrame implements WindowListener { private static int DEFAULT_FPS = 80;
private static final int PWIDTH = 512; private static final int PHEIGHT = 512;
private CubeCanvasGL canvas;
private JTextField rotsTF; private DecimalFormat df = new DecimalFormat("0.#");
public CubeGL(long period) { super("CubeGL (Active)");
Container c = getContentPane(); c.setLayout( new BorderLayout() ); c.add( makeRenderPanel(period), BorderLayout.CENTER);
rotsTF = new JTextField("Rotations: "); rotsTF.setEditable(false); c.add(rotsTF, BorderLayout.SOUTH);
addWindowListener(this);
pack(); setVisible(true); }
private JPanel makeRenderPanel(long period) { JPanel renderPane = new JPanel(); renderPane.setLayout( new BorderLayout() ); renderPane.setOpaque(false); renderPane.setPreferredSize( new Dimension(PWIDTH, PHEIGHT));
canvas = makeCanvas(period); renderPane.add(canvas, BorderLayout.CENTER);
canvas.setFocusable(true); canvas.requestFocus(); renderPane.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent evt) { Dimension d = evt.getComponent().getSize(); canvas.reshape(d.width, d.height); } });
return renderPane; }
private CubeCanvasGL makeCanvas(long period) { GLCapabilities caps = new GLCapabilities();
AWTGraphicsDevice dev = new AWTGraphicsDevice(null); AWTGraphicsConfiguration awtConfig = (AWTGraphicsConfiguration) GLDrawableFactory.getFactory().chooseGraphicsConfiguration(caps, null, dev);
GraphicsConfiguration config = null; if (awtConfig != null) config = awtConfig.getGraphicsConfiguration();
return new CubeCanvasGL(this, period, PWIDTH, PHEIGHT, config, caps); }
public void setRots(float rotX, float rotY, float rotZ) { rotsTF.setText("Rotations: (" + df.format(rotX) + ", " + df.format(rotY) + ", " + df.format(rotZ) + ")"); }
public void windowActivated(WindowEvent e) { canvas.resumeGame(); }
public void windowDeactivated(WindowEvent e) { canvas.pauseGame(); }
public void windowDeiconified(WindowEvent e) { canvas.resumeGame(); }
public void windowIconified(WindowEvent e) { canvas.pauseGame(); }
public void windowClosing(WindowEvent e) { canvas.stopGame(); }
public void windowClosed(WindowEvent e) {} public void windowOpened(WindowEvent e) {}
public static void main(String[] args) { int fps = DEFAULT_FPS; if (args.length != 0) fps = Integer.parseInt(args[0]);
long period = (long) 1000.0/fps; System.out.println("fps: " + fps + "; period: " + period + " ms");
new CubeGL(period*1000000L); }
}
|