Combine Illumination w/ Mouse rotation

This commit is contained in:
PedroEdiaz
2024-10-18 11:54:12 -06:00
parent 7c1f691b46
commit 7c8cfcbfce
3 changed files with 57 additions and 28 deletions

View File

@@ -50,8 +50,7 @@ const char * wname = "manigraph: manifold grapher";
int main( void )
{
float * n_cube, *n_axis;
id_t shader, texture;
id_t shader, texture, shader_plain;
mesh_t m_cube, m_axis;
window_t window;
@@ -63,63 +62,79 @@ int main( void )
glewInit();
if( !( shader = create_shader() ) )
goto error_shader;
gload_program( shader, vs, VERTEX );
gload_program( shader, fs, FRAGMENT );
use_shader( shader );
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
n_cube = fill_normal( d_cube );
n_axis = fill_normal( d_axis );
if( !( m_cube = create_mesh( d_cube, n_cube ) ) )
goto error_mesh_cube;
if( !( m_axis = create_mesh( d_axis, n_axis ) ) )
goto error_mesh_axis;
free( n_cube );
free( n_axis );
texture=create_palette_texture( palette );
use_texture( texture );
if( !( shader = create_shader() ) )
goto error_shader;
gload_program( shader, vs, VERTEX );
gload_program( shader, fs, FRAGMENT );
if( !( shader_plain = create_shader() ) )
goto error_shader_plain;
gload_program( shader_plain, vs, VERTEX );
gload_program( shader_plain, fs_plain, FRAGMENT );
load_fix_matrix( shader, (float)WIDTH/HEIGHT );
load_fix_matrix( shader_plain, (float)WIDTH/HEIGHT );
/* Fill m_cube */
{
float * n_cube;
n_cube = fill_normal( d_cube );
if( !( m_cube = create_mesh( d_cube, n_cube ) ) )
goto error_mesh_cube;
free( n_cube );
}
/* Fill m_axis */
{
float * n_axis;
n_axis = fill_normal( d_axis );
if( !( m_axis = create_mesh( d_axis, n_axis ) ) )
goto error_mesh_axis;
free( n_axis );
}
while( is_open_window( window ) )
{
quat_t q;
q=poll_input( window );
load_rot_matrix( shader, q );
load_rot_matrix( shader_plain, q );
clean_context();
#ifndef DEBUG
load_mdl_matrix( shader, 0, 0 );
load_mdl_matrix( shader_plain, 0, 0 );
draw_mesh( m_axis );
load_mdl_matrix( shader, 1, 1 );
load_mdl_matrix( shader_plain, 1, 1 );
draw_mesh( m_axis );
load_mdl_matrix( shader, 2, 2 );
load_mdl_matrix( shader_plain, 2, 2 );
draw_mesh( m_axis );
#endif
load_mdl_matrix( shader, 0, 3 );
draw_mesh( m_cube );
}
destroy_texture( texture );
destroy_mesh( m_axis );
destroy_mesh( m_cube );
destroy_shader( shader_plain );
destroy_shader( shader );
destroy_texture( texture );
close_window( window );
return 0;
error_mesh_axis:
destroy_mesh( m_cube );
error_mesh_cube:
destroy_shader( shader_plain );
error_shader_plain:
destroy_shader( shader );
error_shader:
close_window( window );
destroy_texture( texture );
error_window:
return 1;
}