// OpenGL Setup Code
// Written by Sjur Julin 2023.
// License: CC BY 4.0 https://creativecommons.org/licenses/by/4.0/
// Read the 2023 article here: https://www.ignorantus.com/pages/nano_fractals/
#ifndef NANOFRAXGLH
#define NANOFRAXGLH

enum KeyCode {
    _0x0_,_0x1_,_0x2_,_0x3_,_0x4_,_0x5_,_0x6_,_0x7_,_0x8_,
    _ESC_,_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_9_,_0_,_SUB_,_EQ_,_BKSPC_,
    _TAB_,_Q_,_W_,_E_,_R_,_T_,_Y_,_U_,_I_,_O_,_P_,_LBRAK_,_BRAKR_,_RETURN_,
    _LCTL_,_A_,_S_,_D_,_F_,_G_,_H_,_J_,_K_,_L_,_SEMI_,_APOS_,_TILDE_,
    _LSHFT_,_BSLASH_,_Z_,_X_,_C_,_V_,_B_,_N_,_M_,_COMMA_,_DOT_,_SLASH_,_RSHFT_,
    _KPMUL_,_LALT_,_SPACE_,_0x42_,_F1_,_F2_,_F3_,_F4_,_F5_,_F6_,_F7_,_F8_,_F9_,_F10_,
    _0x4D_,_0x4E_,_KP7_,_KP8_,_KP9_,_KPSUB_,_KP4_,_KP5_,_KP6_,_KPADD_,_KP1_,_KP2_,_KP3_,
    _KP0_,_KPDOT_,_0x5C_,_0x5D_,_ANGBR_,_F11_,_F12_,_0x61_,_0x62_,_0x63_,_0x64_,_0x65_,_0x66_,_0x67_,
    _KPENTR_,_RCTL_,_KPDIV_,_0x6B_,_ALTR_,_0x6D_,_HOME_,_UP_,_PGUP_,_LEFT_,_RIGHT_,_END_,_DOWN_,_PGDN_,_INS_,_DEL_,_0x78_
};

int XWinCreate(char *title);
void XWinFullscreen(int fullscreen);
void XWinProc(void);
void XWinDestroy(void);
void Draw(void);

typedef struct Vtx {
    float x, y, z, u, v;
} Vtx;

typedef struct Image {
    GLuint w, h, stride, vstride, format, type, datasize, flags;
    uint8_t *data;
} Image;

typedef struct Texture {
    GLuint id;
    GLint min, mag, wrap_s, wrap_t, mipmap;
    GLuint internalformat;
    Image *img;
} Texture;

int InitGL();

void setTexCenter( void );
void setTexBottom( void );

void initUniformBuffer( void *src, int size );
void copyToUniformBuffer( void *src, int size );

Texture *NewTexture(int w, int h);
void UploadTexture(Texture *tex);

extern char keys[256];
extern const char *vs_txt;
extern const char *fs_txt;
extern const char *tx_txt;
extern int quit;
extern GLuint pr1, pr2;

#endif
