2023-09-04 09:48:44 -05:00
|
|
|
#ifndef OPENGL_RENDER_H
|
|
|
|
#define OPENGL_RENDER_H
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-09-05 09:38:52 -05:00
|
|
|
#if defined __linux__
|
|
|
|
#define SOKOL_GLCORE33
|
|
|
|
#elif __EMSCRIPTEN__
|
|
|
|
#define SOKOL_GLES3
|
|
|
|
#elif __WIN32
|
|
|
|
#define SOKOL_GLCORE33
|
|
|
|
#define SOKOL_WIN32_FORCE_MAIN
|
2023-09-15 03:37:07 -05:00
|
|
|
#elif __APPLE__
|
2023-09-18 07:36:07 -05:00
|
|
|
// #define SOKOL_METAL
|
2023-09-15 03:37:07 -05:00
|
|
|
#define SOKOL_GLCORE33
|
2023-09-05 09:38:52 -05:00
|
|
|
#endif
|
|
|
|
|
2023-05-22 00:08:08 -05:00
|
|
|
#include "sokol/sokol_gfx.h"
|
2023-05-30 13:07:18 -05:00
|
|
|
#include "HandmadeMath.h"
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
struct mCamera;
|
|
|
|
struct window;
|
|
|
|
|
|
|
|
extern struct shader *spriteShader;
|
|
|
|
extern struct shader *animSpriteShader;
|
|
|
|
|
|
|
|
extern sg_image ddimg;
|
|
|
|
|
|
|
|
extern struct sprite *tsprite;
|
|
|
|
|
|
|
|
extern int renderMode;
|
|
|
|
|
|
|
|
extern HMM_Vec3 dirl_pos;
|
|
|
|
|
|
|
|
extern HMM_Mat4 projection;
|
|
|
|
extern HMM_Mat4 hudproj;
|
|
|
|
|
2023-09-15 03:37:07 -05:00
|
|
|
struct draw_p {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
extern float gridScale;
|
|
|
|
extern float smallGridUnit;
|
|
|
|
extern float bigGridUnit;
|
|
|
|
extern float gridSmallThickness;
|
|
|
|
extern float gridBigThickness;
|
|
|
|
extern struct rgba gridBigColor;
|
|
|
|
extern struct rgba gridSmallColor;
|
|
|
|
extern float gridOpacity;
|
|
|
|
extern float editorFOV;
|
|
|
|
extern float shadowLookahead;
|
|
|
|
extern char objectName[];
|
|
|
|
extern int debugColorPickBO;
|
|
|
|
|
|
|
|
extern struct gameobject *selectedobject;
|
|
|
|
|
|
|
|
#include <chipmunk/chipmunk.h>
|
|
|
|
|
|
|
|
enum RenderMode {
|
|
|
|
LIT,
|
|
|
|
UNLIT,
|
|
|
|
WIREFRAME,
|
|
|
|
DIRSHADOWMAP,
|
|
|
|
OBJECTPICKER
|
|
|
|
};
|
|
|
|
|
|
|
|
void render_init();
|
|
|
|
void openglRender(struct window *window);
|
|
|
|
void opengl_rendermode(enum RenderMode r);
|
|
|
|
|
|
|
|
void openglInit3d(struct window *window);
|
|
|
|
void openglRender3d(struct window *window, struct mCamera *camera);
|
|
|
|
|
|
|
|
void render_winsize();
|
|
|
|
|
|
|
|
void debug_draw_phys(int draw);
|
|
|
|
|
|
|
|
void set_cam_body(cpBody *body);
|
|
|
|
cpVect cam_pos();
|
|
|
|
float cam_zoom();
|
|
|
|
void add_zoom(float val);
|
2023-09-18 07:36:07 -05:00
|
|
|
HMM_Vec2 world2screen(HMM_Vec2 pos);
|
|
|
|
HMM_Vec2 screen2world(HMM_Vec2 pos);
|
2023-09-04 09:48:44 -05:00
|
|
|
|
|
|
|
sg_shader sg_compile_shader(const char *v, const char *f, sg_shader_desc *d);
|
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
void gif_rec_start(int w, int h, int cpf, int bitdepth);
|
2023-09-11 15:07:36 -05:00
|
|
|
void gif_rec_end(char *path);
|
|
|
|
|
2023-05-16 01:31:13 -05:00
|
|
|
struct uv_n {
|
|
|
|
unsigned short u;
|
|
|
|
unsigned short v;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct st_n {
|
|
|
|
struct uv_n s;
|
|
|
|
struct uv_n t;
|
|
|
|
};
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
struct rgba {
|
|
|
|
unsigned char r;
|
|
|
|
unsigned char g;
|
|
|
|
unsigned char b;
|
|
|
|
unsigned char a;
|
|
|
|
};
|
|
|
|
|
2023-05-30 13:07:18 -05:00
|
|
|
struct boundingbox {
|
|
|
|
float t;
|
|
|
|
float b;
|
|
|
|
float r;
|
|
|
|
float l;
|
|
|
|
};
|
|
|
|
|
2023-09-05 09:38:52 -05:00
|
|
|
struct rect {
|
|
|
|
float h, w, x, y;
|
|
|
|
};
|
|
|
|
|
2023-05-30 13:07:18 -05:00
|
|
|
static struct boundingbox cwh2bb(HMM_Vec2 c, HMM_Vec2 wh) {
|
|
|
|
struct boundingbox bb = {
|
|
|
|
.t = c.Y + wh.Y/2,
|
|
|
|
.b = c.Y - wh.Y/2,
|
|
|
|
.r = c.X + wh.X/2,
|
|
|
|
.l = c.X - wh.X/2
|
|
|
|
};
|
|
|
|
|
|
|
|
return bb;
|
|
|
|
}
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
static float *rgba2floats(float *r, struct rgba c)
|
|
|
|
{
|
|
|
|
r[0] = c.r / 255.0;
|
|
|
|
r[1] = c.g / 255.0;
|
|
|
|
r[2] = c.b / 255.0;
|
|
|
|
r[3] = c.a / 255.0;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2023-05-22 00:08:08 -05:00
|
|
|
static sg_blend_state blend_trans = {
|
|
|
|
.enabled = true,
|
|
|
|
.src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
|
|
|
|
.dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.src_factor_alpha = SG_BLENDFACTOR_SRC_ALPHA,
|
2023-09-04 01:20:55 -05:00
|
|
|
.dst_factor_alpha = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
|
2023-05-22 00:08:08 -05:00
|
|
|
};
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#endif
|