// -*- compile-command: "javac -cp libs/lwjgl.jar Triangle.java" -*- */ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.Display; import org.lwjgl.opengl.DisplayMode; import org.lwjgl.LWJGLException; class Triangle { static float angle = 0.0f; final static float v1_x = (float)Math.cos(Math.PI * (1.0f / 6.0f)); final static float v1_y = (float)Math.sin(Math.PI * (1.0f / 6.0f)); final static float v2_x = (float)Math.cos(Math.PI * (5.0f / 6.0f)); final static float v2_y = (float)Math.sin(Math.PI * (5.0f / 6.0f)); final static float v3_x = (float)Math.cos(Math.PI * (9.0f / 6.0f)); final static float v3_y = (float)Math.sin(Math.PI * (9.0f / 6.0f)); private void init() { GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(-1.2f, 1.2f, -1.2f, 1.2f, -1.0f, 1.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); } private void display() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glPushMatrix(); GL11.glRotatef(angle, 0.0f, 0.0f, 1.0f); GL11.glBegin(GL11.GL_TRIANGLES); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glVertex2f(v1_x, v1_y); GL11.glColor3f(0.0f, 1.0f, 0.0f); GL11.glVertex2f(v2_x, v2_y); GL11.glColor3f(0.0f, 0.0f, 1.0f); GL11.glVertex2f(v3_x, v3_y); GL11.glEnd(); GL11.glPopMatrix(); } private void start() { try { Display.setTitle("Triangle!"); Display.setDisplayMode(new DisplayMode(512, 512)); Display.create(); } catch (LWJGLException e) { System.err.println("Could't create display. Exiting"); System.exit(0); } init(); while (!Display.isCloseRequested()) { angle += 0.02f; display(); Display.update(); } Display.destroy(); } public static void main(String[] args) { new Triangle().start(); } }