Woo hoo! I got it to work!

Now the trick is getting it to compile. I'm taking the code directly from the skeleton code from the documentation at java-game-lib.sourceforge.net. Here are my problems:
Display.Create(...) Doesn't exist anymore. What replaced it?
It doesn't know what GL is. Do I need to reference other .jar files other than lwjgl.jar?
it say swapBuffers(...) is private. So how do I use it?
And it has no idea what display.destroy is. For reference, I've posted the code I copied below.
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 148 149 150
| import org.lwjgl.*; import org.lwjgl.opengl.*; import org.lwjgl.input.*;
import java.nio.*;
public final class Game { static { try { int mode = -1; DisplayMode[] modes = Display.getAvailableDisplayModes(); for (int i = 0; i < modes.length; i++) { if (modes[i].width == 640 && modes[i].height == 480 && modes[i].bpp >= 16) { mode = i; break; } }
Display.create(modes[mode], false); System.out.println("Created display."); } catch (Exception e) { System.err.println("Failed to create display due to " + e); System.exit(1); } }
public static final GL gl = new GL(); public static final GLU glu = new GLU(gl);
static { try { gl.create(); System.out.println("Created OpenGL."); } catch (Exception e) { System.err.println("Failed to create OpenGL due to " + e); System.exit(1); } }
private static boolean finished;
private static float angle;
private Game() { }
public static void main(String[] arguments) { try { init(); while (!finished) { Keyboard.poll();
mainLoop();
render();
gl.swapBuffers(); } } catch (Throwable t) { t.printStackTrace(); } finally { cleanup(); } }
private static void mainLoop() { angle += 1f; if (angle > 360.0f) angle = 0.0f;
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { finished = true; } }
private static void render() { gl.clear(GL.COLOR_BUFFER_BIT); gl.pushMatrix(); gl.translatef(Display.getWidth() / 2, Display.getHeight() / 2, 0.0f); gl.rotatef(angle, 0, 0, 1.0f); gl.begin(GL.QUADS); { gl.vertex2i(-50, -50); gl.vertex2i(50, -50); gl.vertex2i(50, 50); gl.vertex2i(-50, 50); } gl.end(); gl.popMatrix(); }
private static void init() throws Exception { System.out.println("Press the ESCAPE key to exit"); Keyboard.create();
Sys.setTime(0);
Sys.setProcessPriority(Sys.LOW_PRIORITY);
System.out.println("Timer resolution: " + Sys.getTimerResolution() + " ticks per second");
gl.matrixMode(GL.PROJECTION); gl.loadIdentity(); glu.ortho2D(0, Display.getWidth(), 0, Display.getHeight()); gl.matrixMode(GL.MODELVIEW); gl.loadIdentity(); gl.viewport(0, 0, Display.getWidth(), Display.getHeight());
ByteBuffer num_tex_units_buf = ByteBuffer.allocateDirect(4); num_tex_units_buf.order(ByteOrder.nativeOrder()); int buf_addr = Sys.getDirectBufferAddress(num_tex_units_buf); gl.getIntegerv(GL.MAX_TEXTURE_UNITS_ARB, buf_addr);
System.out.println( "Number of texture units: " + num_tex_units_buf.getInt()); }
private static void cleanup() { Keyboard.destroy(); gl.destroy(); Display.destroy(); } } |