import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;



public class Game_Skeleton
{
    float cameraY  = 300;
    float cameraZ  = 700;

	public boolean done = false;
	private DisplayMode displayMode;

	public Game_Skeleton()
	{
		try
		{
		DisplayMode d[] = Display.getAvailableDisplayModes();
		for(int i = 0; i<d.length; i++)
		{
			if(d[i].getWidth() == 800 
					&& d[i].getHeight() == 600
					&& d[i].getBitsPerPixel() == 32)
			{
				displayMode = d[i];
				//System.out.println(d[i].getHeight()+"*"+d[i].getWidth());
				break;
			}
		}
		Display.setTitle("PongPong");
		Display.setFullscreen(false);
		Display.create();
		//Display.create(new PixelFormat(0,24,0));
		}
		catch(Exception e)
		{
			System.err.println("Error");
			System.exit(1);
		}
	}


    public void run() {
        try {
            init();
            while (!done) {
            	process_keyboard();
                render();
                Display.update();
            }
            cleanup();
        }
        catch (Exception e) { //or catch(Throwable e)
            e.printStackTrace();
            System.exit(0);
        }
    }
	
	public void init() throws Exception
	{
		GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
		/*GL11.glOrtho(
				0, 800f, 
				0, 600f,
				-5, 100);*/
        GLU.gluPerspective(
                30.0f,        // Field Of View
                (float)displayMode.getWidth() / (float)displayMode.getHeight(), // aspect ratio
                //800/600,
                .1f,         // near Z clipping plane
                10000.0f);      // far Z clipping plane
        System.out.println("init");
            // Where is the 'eye'
        /*GLU.gluLookAt(
                400f, 300f, 700f,   // eye position
                400f, 300f, -5f,    // target to look at
                0f, 1f, 0f);   // which way is up  */      
        // OpenGL won't draw backward facing triangles ("back faces")
        GL11.glEnable(GL11.GL_CULL_FACE);
	}
    
	public void render()
	{
		GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glLoadIdentity();
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
        GLU.gluPerspective(
                40.0f,        // Field Of View
                (float)displayMode.getWidth() / (float)displayMode.getHeight(), // aspect ratio
                //800/600,
                .1f,         // near Z clipping plane
                1000.0f);      // far Z clipping plane

            // Where is the 'eye'*/
        GLU.gluLookAt(
                400f, cameraY, cameraZ,   // eye position
                400f, 300f, -5f,    // target to look at
                0f, 1f, 0f);   // which way is up
        GL11.glMatrixMode(GL11.GL_MODELVIEW);

        //GL11.glEnable(GL11.GL_DEPTH_TEST);
	}

	public void process_keyboard()
	{     
		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT)){
    		cameraZ -= 5;
    	}
    	if(Keyboard.isKeyDown(Keyboard.KEY_LEFT)){
    		cameraZ += 5;
    	}
    	if(Keyboard.isKeyDown(Keyboard.KEY_UP)){
    		cameraY += 5;
    	}
    	if(Keyboard.isKeyDown(Keyboard.KEY_DOWN)){
    		cameraY -= 5;
    	}
	}
	

	public void cleanup()
	{
		/* Destroy the keyboard */
		Keyboard.destroy();
		/* Destroy the windows */
		Display.destroy();
		SoundScape.destroy();
	}
}



