Files
manigraph/src/main.h
2024-12-01 12:19:53 -06:00

165 lines
3.2 KiB
C

/*
If DEBUG is set, we show the triangles of the mesh,
without illumination, and we write the compilation
error of the shaders.
*/
/* #define DEBUG */
#define GLAD
typedef const void * window_t;
typedef unsigned int id_t;
typedef void * mesh_t;
typedef float * quat_t;
typedef float * mat4_t;
/*
This struct represent the proyection, where:
mesh: data of surface.
m: the dimention of the surface.
x: the coordanate of the x axis.
y: the coordanate of the y axis.
z: the coordanate of the z axis.
w: the coordanate of the w axis.
*/
struct projection
{
mesh_t mesh;
unsigned char m, x, y, z, w;
};
/*
Init window:
w: default width;
h: default height;
name: Name of the window.
*/
window_t init_window(unsigned int w, unsigned int h, const char * name);
void use_window(window_t window);
int is_open_window(window_t window);
void close_window(window_t window);
/*
Create mesh:
d: array of floats with the vertex data.
n: array of floats with the normal data.
m: Dimention of mesh
*/
mesh_t create_mesh( float * d, float * n, unsigned char m );
void set_projection_mesh( struct projection );
void destroy_mesh(mesh_t p);
void draw_mesh(mesh_t p);
void draw_mesh_lines(mesh_t p);
/*
Set background color:
r: red value in hex.
g: green value in hex.
b: blue value in hex.
*/
void set_clean_color_context(unsigned char r, unsigned char g, unsigned char b);
void clean_context(void);
int init_context( void );
void destroy_shader(id_t shader);
id_t create_shader(void);
void use_shader(id_t shader);
enum
{
VERTEX, FRAGMENT
};
/*
Load program to shader:
src: GLSL source code as string.
type: VERTEX or FRAGMENT
*/
unsigned char load_program_to_shader(id_t shader, const char * src, unsigned int type);
/*
load float to shader:
var: name of glsl variable.
f: float to load
*/
void load_float_to_shader(id_t shader, char * var, float f);
/*
load unsigned int to shader:
var: name of glsl variable.
u: unsigned int to load
*/
void load_uint_to_shader(id_t shader, char * var, unsigned int u);
/*
load matrix 4 to shader:
var: name of glsl variable.
m: Matrix to load
*/
void load_mat4_to_shader(id_t shader, char * var, mat4_t m);
/*
Generate and load fix matrix, this matrix
has the information of the perspective and
camera information.
ratio: default ratio of window.
*/
void load_fix_matrix(id_t shader, float ratio);
/*
Generate and load model matrix, it also sets the color
to draw.
i: From {0,1,2} select one of 3 ortogonal rotations,
One for each axis.
c: Color index of the pallete.
*/
void load_mdl_matrix(id_t shader, unsigned char i, unsigned char c);
/*
Generate and load rotation matrix.
q: quaterinon describing the rotation.
*/
void load_rot_matrix(id_t shader, quat_t q);
id_t config_texture(unsigned short type);
void use_texture(id_t texture);
void destroy_texture(id_t texture);
/*
Set color palette as texture:
colors: array of color values (rgba in hex ).
n: number of color on colors.
*/
id_t create_palette_texture(const unsigned char colors[][4], unsigned char n );
quat_t poll_input(window_t window);
#ifdef EMSCRIPTEN
#ifdef GLAD
#error undefine GLAD on src/main.h please
#endif
#endif