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
|
2023-09-19 12:35:12 -05:00
|
|
|
#define SOKOL_D3D11
|
2023-09-15 03:37:07 -05:00
|
|
|
#elif __APPLE__
|
2023-09-18 21:55:37 -05:00
|
|
|
#define SOKOL_METAL
|
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"
|
2024-03-20 16:48:03 -05:00
|
|
|
#include "gameobject.h"
|
2023-05-30 13:07:18 -05:00
|
|
|
|
2023-09-23 12:35:02 -05:00
|
|
|
#define RGBA_MAX 255
|
|
|
|
|
2023-12-22 11:50:03 -06:00
|
|
|
#include "window.h"
|
2023-09-04 09:48:44 -05:00
|
|
|
|
2023-12-22 11:50:03 -06:00
|
|
|
extern struct rgba color_white;
|
|
|
|
extern struct rgba color_black;
|
2024-03-13 03:51:44 -05:00
|
|
|
extern struct rgba color_clear;
|
2023-09-04 09:48:44 -05:00
|
|
|
|
|
|
|
extern int renderMode;
|
|
|
|
|
|
|
|
extern HMM_Vec3 dirl_pos;
|
|
|
|
|
|
|
|
extern HMM_Mat4 projection;
|
|
|
|
extern HMM_Mat4 hudproj;
|
2024-03-27 15:00:59 -05:00
|
|
|
extern HMM_Mat4 useproj;
|
2024-04-17 08:57:45 -05:00
|
|
|
extern sg_pass_action pass_action;
|
2024-03-27 15:00:59 -05:00
|
|
|
|
2024-04-23 15:58:08 -05:00
|
|
|
extern sg_buffer sprite_quad;
|
|
|
|
extern sg_sampler std_sampler;
|
|
|
|
|
2023-09-15 03:37:07 -05:00
|
|
|
struct draw_p {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
|
|
|
|
2024-04-20 12:55:20 -05:00
|
|
|
struct draw_p3 {
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
float z;
|
|
|
|
};
|
|
|
|
|
2023-09-04 09:48:44 -05:00
|
|
|
#include <chipmunk/chipmunk.h>
|
|
|
|
|
|
|
|
enum RenderMode {
|
|
|
|
LIT,
|
|
|
|
UNLIT,
|
|
|
|
WIREFRAME,
|
|
|
|
DIRSHADOWMAP,
|
|
|
|
OBJECTPICKER
|
|
|
|
};
|
|
|
|
|
|
|
|
void render_init();
|
2024-03-20 16:48:03 -05:00
|
|
|
extern HMM_Vec2 campos;
|
|
|
|
extern float camzoom;
|
|
|
|
|
|
|
|
void openglRender(struct window *window, gameobject *cam, float zoom);
|
2023-09-04 09:48:44 -05:00
|
|
|
void opengl_rendermode(enum RenderMode r);
|
|
|
|
|
|
|
|
void openglInit3d(struct window *window);
|
2023-12-21 17:21:01 -06:00
|
|
|
void capture_screen(int x, int y, int w, int h, const char *path);
|
2023-09-04 09:48:44 -05:00
|
|
|
|
2023-09-12 00:02:57 -05:00
|
|
|
void gif_rec_start(int w, int h, int cpf, int bitdepth);
|
2023-12-21 17:21:01 -06:00
|
|
|
void gif_rec_end(const char *path);
|
2023-09-11 15:07:36 -05:00
|
|
|
|
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-12-29 19:08:53 -06:00
|
|
|
typedef struct rgba rgba;
|
|
|
|
|
2024-01-01 17:30:42 -06:00
|
|
|
static inline rgba vec2rgba(HMM_Vec4 v) {
|
|
|
|
return (rgba){v.e[0]*255,v.e[1]*255,v.e[2]*255,v.e[3]*255};
|
|
|
|
}
|
|
|
|
|
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 {
|
2024-03-13 03:51:44 -05:00
|
|
|
float x,y,w,h;
|
2023-05-22 00:08:08 -05:00
|
|
|
};
|
2024-03-13 03:51:44 -05:00
|
|
|
typedef struct rect rect;
|
2023-05-22 00:08:08 -05:00
|
|
|
|
2023-12-22 11:50:03 -06:00
|
|
|
struct boundingbox cwh2bb(HMM_Vec2 c, HMM_Vec2 wh);
|
|
|
|
float *rgba2floats(float *r, struct rgba c);
|
|
|
|
extern sg_blend_state blend_trans;
|
2024-01-01 07:44:43 -06:00
|
|
|
|
2024-01-02 07:55:22 -06:00
|
|
|
static inline float lerp(float f, float a, float b)
|
2024-01-01 07:44:43 -06:00
|
|
|
{
|
|
|
|
return a * (1.0-f)+(b*f);
|
|
|
|
}
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#endif
|