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 151 152
| import org.lwjgl.*; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL; import org.lwjgl.opengl.GLU;
public class BaseWindow {
public BaseWindow() { fullscreen = true; done = false; }
protected void resizeGLScene(int i, int j) { gl.viewport(0, 0, i, j); gl.matrixMode(5889); gl.loadIdentity(); glu.perspective(45D, (float)i / (float)j, 0.10000000149011612D, 100D); gl.matrixMode(5888); gl.loadIdentity(); }
protected void initGL() throws Exception { gl.shadeModel(7425); gl.clearColor(0.0F, 0.0F, 0.0F, 0.0F); gl.clearDepth(1.0D); gl.enable(2929); gl.depthFunc(515); gl.hint(3152, 4354); }
protected boolean drawGLScene(float f) { gl.clear(16640); gl.loadIdentity(); return true; }
protected void killGLWindow() { Mouse.destroy(); Keyboard.destroy(); gl.destroy(); }
protected void createGLWindow(int i, int j, int k, boolean flag) throws Exception { fullscreen = flag; try { byte byte0 = -1; DisplayMode adisplaymode[] = Display.getAvailableDisplayModes(); int i1 = 0; do { if(i1 >= adisplaymode.length) break; if(adisplaymode[i1].width == i && adisplaymode[i1].height == j && adisplaymode[i1].bpp >= k) { int l = i1; break; } i1++; } while(true); gl = new GL("LWJGL Example", 50, 50, i, j, k, 0, 0, 0); gl.create(); glu = new GLU(gl); Keyboard.create(); Keyboard.enableBuffer(); Mouse.create(); resizeGLScene(i, j); initGL(); } catch(Exception exception) { throw new Exception("Problem initialising Lesson", exception); } }
protected void start(int i, int j, int k, boolean flag) throws Exception { long l = 0L; timerRes = Sys.getTimerResolution(); if(timerRes == 0L) throw new Exception("There are no timers availible!"); try { createGLWindow(i, j, k, flag); long l1; do { gl.tick(); l1 = Sys.getTime(); Sys.setTime(0L); } while(!loop((float)l1 / (float)timerRes)); killGLWindow(); } catch(Exception exception) { throw new Exception("Problem starting loop", exception); } }
protected boolean loop(float f) { if(!drawGLScene(f)) { return true; } else { gl.paint(); input(f); return done; } }
protected void input(float f) { Keyboard.poll(); if(Keyboard.isKeyDown(1)) done = true; }
public static void main(String args[]) { int i = 0; BaseWindow basewindow = new BaseWindow(); try { basewindow.start(640, 480, 16, true); } catch(Exception exception) { i = 1; exception.printStackTrace(); } System.exit(i); }
protected GL gl; protected GLU glu; protected boolean fullscreen; protected boolean done; protected long timerRes; } |