import keel.runtime.KeelRuntime; import keel.runtime.Application; import keel.gfx.GLGraphics; import keel.gfx.GLConstants; import keel.gfx.PixelFormat; import keel.runtime.event.KeyListener; import keel.runtime.event.KeyEvent; public class OpenWindow implements Application { private int width = 640; private int height = 480; public void keelMain(KeelRuntime keelRuntime, String[] args) { keelRuntime.addKeyListener(new DemoKeyListener(keelRuntime)); keelRuntime.createWindow("your first KEEL program", 640, 480); keelRuntime.createGraphicsWithDefaultPixelFormat(); keelRuntime.run(); System.out.println("Never called."); } public void initGraphics(GLGraphics glGraphics) { glGraphics.glOrtho(0, width, 0, height, -1, 1); glGraphics.glScalef(1.0f, -1.0f, 1.0f); glGraphics.glTranslatef(0, -height, 0); } public void update(GLGraphics glGraphics) { glGraphics.glClear(GLConstants.GL_COLOR_BUFFER_BIT); drawTriangle(glGraphics); glGraphics.glFlush(); } public void quitRequested() { } private void drawTriangle(GLGraphics glGraphics) { int topY = height / 3; int bottomY = (height / 3) * 2; int centerX = width / 2; int leftX = width / 3; int rightX = (width / 3) * 2; glGraphics.glBegin(GLConstants.GL_TRIANGLES); glGraphics.glColor3f(1.0f, 1.0f, 1.0f); glGraphics.glVertex2i(leftX, bottomY); glGraphics.glVertex2i(rightX, bottomY); glGraphics.glVertex2i(centerX, topY); glGraphics.glEnd(); } class DemoKeyListener implements KeyListener { public DemoKeyListener(KeelRuntime aKeelRuntime) { keelRuntime = aKeelRuntime; } public void keyTyped(KeyEvent event) { System.out.println(event); } public void keyPressed(KeyEvent event) { System.out.println(event); if (event.getKeyCode() == KeyEvent.VK_Q) { keelRuntime.disposeDisplay(); System.exit(0); } } public void keyReleased(KeyEvent event) { System.out.println(event); } private KeelRuntime keelRuntime; } }