Merge: crisel -> main

This commit is contained in:
PedroEdiaz
2024-10-22 11:45:51 -06:00
parent 17e1cf8804
commit 6eedd09e2c
6 changed files with 105 additions and 24 deletions

View File

@@ -4,6 +4,7 @@
#include <stdlib.h>
#include <cglm/vec3.h>
#include <stdio.h>
#define WIDTH 512
#define HEIGHT 512
@@ -51,72 +52,99 @@ float * fill_normal( float * d )
const char * wname = "manigraph: manifold grapher";
float * generate_surface(unsigned int, unsigned char *m);
int main( void )
void mlog(char * msg)
{
#ifdef DEBUG
printf(msg);
#endif
}
int main(void)
{
id_t shader, texture, shader_plain;
mesh_t m_surface, m_axis;
window_t window;
/* Setup window */
mlog("[VENTANA] Inicializando...\n");
{
if(!(window = init_window(WIDTH, HEIGHT, wname)))
{
mlog("[VENTANA] Error al inicializar...\n");
goto error_window;
}
use_window(window);
set_clean_color_context(0x2E, 0x07, 0x3F);
}
/* Setup context */
mlog("[CONTEXT] Inicializando...\n");
{
if(!(init_context()))
{
mlog("[CONTEXT] Error al inicializar...\n");
goto error_context;
}
}
/* Setup color texture */
mlog("[TEXTURE] Inicializando...\n");
{
texture=create_palette_texture(palette, 4);
use_texture(texture);
}
/* Setup shader */
mlog("[SHADER] Inicializando...\n");
{
if(!(shader = create_shader()))
{
mlog("[SHADER] Error al inicializar...\n");
goto error_shader;
}
load_program_to_shader(shader, vs, VERTEX);
load_program_to_shader(shader, fs, FRAGMENT);
load_fix_matrix(shader, (float)WIDTH/HEIGHT);
}
/* Setup shader w/out illumination */
mlog("[SHADER] Inicializando...\n");
{
if(!(shader_plain = create_shader()))
{
mlog("[SHADER] Error al inicializar...\n");
goto error_shader_plain;
}
load_program_to_shader(shader_plain, vs, VERTEX);
load_program_to_shader(shader_plain, fs_plain, FRAGMENT);
load_fix_matrix(shader_plain, (float)WIDTH/HEIGHT);
}
/* Fill mesh of surface */
mlog("[MESH] Inicializando...\n");
{
unsigned char m;
float * n_surface, *d_surface;
d_surface = generate_surface(16,&m);
n_surface = fill_normal(d_surface);
if( !(m_surface = create_mesh(d_surface, n_surface, coordanate)))
{
mlog("[MESH] Error al inicializar...\n");
goto error_mesh_surface;
}
free(n_surface);
free(d_surface);
}
/* Fill mesh of axis */
mlog("[MESH] Inicializando...\n");
{
float * n_axis;
n_axis = fill_normal(d_axis);
if(!(m_axis = create_mesh(d_axis, n_axis, coordanate)))
{
mlog("[MESH] Error al inicializar...\n");
goto error_mesh_axis;
}
free(n_axis);
}
mlog("[MAIN LOOP] Inicializando...\n");
while(is_open_window(window))
{
quat_t q;
@@ -138,27 +166,41 @@ int main( void )
load_mdl_matrix(shader_plain, 0, 3);
#endif
draw_mesh(m_surface);
}
mlog("[MAIN LOOP] Terminando...\n");
mlog("[MESH] Destruyendo...\n");
destroy_mesh(m_axis);
mlog("[MESH] Destruyendo...\n");
destroy_mesh(m_surface);
mlog("[SHADER] Destruyendo...\n");
destroy_shader(shader_plain);
mlog("[SHADER] Destruyendo...\n");
destroy_shader(shader);
mlog("[TEXTURE] Destruyendo...\n");
destroy_texture(texture);
mlog("[WINDOW] Destruyendo...\n");
close_window(window);
return 0;
mlog("[MESH] Destruyendo...\n");
destroy_mesh(m_axis);
error_mesh_axis:
mlog("[MESH] Destruyendo...\n");
destroy_mesh(m_surface);
error_mesh_surface:
mlog("[SHADER] Destruyendo...\n");
destroy_shader(shader_plain);
error_shader_plain:
mlog("[SHADER] Destruyendo...\n");
destroy_shader(shader);
error_shader:
close_window(window);
mlog("[TEXTURE] Destruyendo...\n");
destroy_texture(texture);
error_context:
mlog("[WINDOW] Destruyendo...\n");
close_window(window);
error_window:
return 1;
}