package demo;

import javax.media.opengl.*;
import jocode.*;

/**
 * Run a bare-bones JOApp.  Draws one white triangle centered on screen.
 * <P>
 * JOApp initializes JOGL for OpenGL rendering,
 * ie. creates a window, sets the display mode, inits glCanvas, mouse and keyboard listeners.
 * <P>
 * napier at potatoland dot org
 */
public class DemoHelloWorld extends JOApp {

	/**
	 * Start the application.  run() calls setup(), handles mouse and keyboard input, preps the OpenGL context.
	 */
    public static void main(String args[]) {
    	// create the app
    	DemoHelloWorld demo = new DemoHelloWorld();

    	// set title, window size
    	windowTitle   = "Hello World";
    	displayWidth  = 640;
    	displayHeight = 480;

    	// start running: will call init(), setup(), draw(), mouse functions
    	demo.run();
    }

    /**
     * Initialize settings.  Will be called once when app starts.  Called by JOApp.init().
     * For now the default settings will be fine, so no code here.
     */
    @Override
    public void setup() {
    }

    /**
     * Render one frame.  Called by the JOApp.display() callback function.
     */
    @Override
    public void draw() {
        // Clear screen and depth buffer
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        // Select The Modelview Matrix (controls model orientation)
        gl.glMatrixMode(GL.GL_MODELVIEW);
        // Reset the coordinate system to center of screen
        gl.glLoadIdentity();
        // Place the viewpoint
        glu.gluLookAt(
            0f, 0f, 10f,   // eye position (10 units in front of the origin)
            0f, 0f, 0f,    // target to look at (the origin)
            0f, 1f, 0f);   // which way is up (Y axis)

        // draw a triangle centered around 0,0,0
        gl.glBegin(GL.GL_TRIANGLES);           // draw triangles
            gl.glVertex3f( 0.0f, 1.0f, 0.0f);         // Top
            gl.glVertex3f(-1.0f,-1.0f, 0.0f);         // Bottom Left
            gl.glVertex3f( 1.0f,-1.0f, 0.0f);         // Bottom Right
        gl.glEnd();                              // done
    }
}
