#ifndef _OPEN_WINDOW_H_
#define _OPEN_WINDOW_H_

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#include "../deps/include/glad/glad.h"

#ifndef _WIN32

#define Window X11Window
#include <GL/glx.h>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#undef  Window

typedef struct {
    GLXFBConfig config;
    GLXContext context;
} GLX;

typedef struct {
    Display * display;
    X11Window window;
    Colormap cmap;
    long eventMask;
} X11;
      
typedef struct Window Window;
typedef void(* WindowEventHandler)(Window * w, XEvent xev);

typedef struct Window {
    GLX glx;
    X11 x;
    WindowEventHandler eventHandler;
    bool close;
} Window;

#else

typedef struct {
} WGL;

typedef struct {
    HDC  display;
    HWND window;
} Windows;

typedef struct Window Window;

typedef struct Window {
    WGL wgl;
    Windows x;
    WindowEventHandler eventHandler;
    bool close;
} Window;

#endif // _WIN32

// depends on glad
int getOpenGLProcs(void);

Window openWindow(const char * name, size_t width, size_t height);
void windowDraw(Window window);
void windowSetEventHandler(Window * window, WindowEventHandler handler);
void windowHandleEvents(Window * window);
void closeWindow(Window w);

#endif  // _OPEN_WINDOW_H_
        
// TODO: Add all the error handling to the glx
