package com.jukusoft.renderer2d.prototyp;

import com.jukusoft.renderer2d.prototyp.engine.window.IWindow;
import com.jukusoft.renderer2d.prototyp.engine.glfw.GLFWUtils;
import com.jukusoft.renderer2d.prototyp.engine.glfw.GLFWWindow;
import com.jukusoft.renderer2d.prototyp.engine.window.callback.AbstractKeyCallback;
import com.jukusoft.renderer2d.prototyp.engine.window.callback.KeyCallback;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

/**
 * Created by Justin on 21.08.2016.
 */
public class Main {

    public static void main (String[] args) {
        //configure log4j to log to console
        BasicConfigurator.configure();

        //log message
        Logger.getRootLogger().info("initialize GLFW now.");

        //initialize GLFW
        GLFWUtils.init();

        //create new GLFW window
        IWindow window = new GLFWWindow(600, 400, "Window title");
        window.create();

        //set window title
        window.setTitle("Window Title");

        //set key callback
        window.addKeyCallback(new AbstractKeyCallback() {
            @Override
            public boolean keyPressed(int key) {
                Logger.getRootLogger().info("key pressed.");

                //execute other callbacks
                return true;
            }

            @Override
            public boolean keyReleased(int key) {
                Logger.getRootLogger().info("key released.");

                //execute other callbacks
                return true;
            }
        });

        //show window
        window.setVisible(true);

        //TODO: add code here

        try {
            //wait 5 seconds
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //close window
        window.destroy();

        //log message
        Logger.getRootLogger().info("shutdown GLFW now.");

        //shutdown GLFW
        GLFWUtils.shutdownGLFW();
    }

}

@@ -462,16 +462,230 @@
 ogger;%0A%0A
+import static org.lwjgl.glfw.GLFW.glfwPollEvents;%0Aimport static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;%0Aimport static org.lwjgl.opengl.GL11.glClear;%0Aimport static org.lwjgl.opengles.GLES20.GL_COLOR_BUFFER_BIT;%0A%0A
 /**%0A * C
@@ -1810,42 +1810,158 @@
   //
-TODO: add code here%0A%0A        try %7B
+renderer loop%0A        while (!window.shouldClose()) %7B%0A            //clear framebuffer%0A            glClear(GL_COLOR_BUFFER_BIT %7C GL_DEPTH_BUFFER_BIT);%0A
 %0A   
@@ -1975,63 +1975,72 @@
   //
+s
 wa
-it 5 seconds%0A            Thread.sleep(5000
+p back and front buffers%0A            window.swap(
 );%0A
+%0A
         
 %7D ca
@@ -2039,72 +2039,142 @@
     
-%7D catch (InterruptedException e) %7B%0A            e.printStackTrace
+    // Poll for window events. The key callback above will only be%0A            // invoked during this call.%0A            glfwPollEvents
 ();%0A

change class Main, added renderer loop.