#include <stdio.h>

#include "GL/gl.h"

#include "src/openwindow.h"

void handleInput(Window * window) {
    if (windowKeyPressed(window, WINDOW_KEY_A))
        printf("A is being pressed\n");

    if (windowKeyHeld(window, WINDOW_KEY_A))
        printf("A is being held\n");

    if (windowKeyReleased(window, WINDOW_KEY_A))
        printf("A is being released\n");
}

int main(void)
{
    Window * w = openWindow("Window", 800, 600);

    while (!windowKeyPressed(w, WINDOW_KEY_ESC)) {
        windowHandleEvents(w);

        handleInput(w);

        glClearColor(0.1, 0.2, 0.3, 1);
        glClear(GL_COLOR_BUFFER_BIT);
        glViewport(0, 0, 800, 600);
        glBegin(GL_TRIANGLES);
            glColor3f(1.0f, 0.0f, 0.0f);
            glVertex2f(-0.5, -0.5);
            glColor3f(0.0f, 1.0f, 0.0f);
            glVertex2f(0.5, -0.5);
            glColor3f(0.0f, 0.0f, 1.0f);
            glVertex2f(0.0, 0.5);
        glEnd();
        glFlush();

        windowDraw(w);
    }

    closeWindow(w);

    return 0;
}
