2 * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved
8 vg_tex2d tex_norwey
= { .path
= "textures/norway_foliage.qoi" };
9 vg_tex2d tex_grid
= { .path
= "textures/grid.qoi" };
10 vg_tex2d tex_sky
= { .path
= "textures/sky.qoi" };
11 vg_tex2d tex_gradients
= { .path
= "textures/gradients.qoi",
12 .flags
= VG_TEXTURE_CLAMP
};
13 vg_tex2d tex_cement
= { .path
= "textures/cement512.qoi" };
14 vg_tex2d tex_water
= { .path
= "textures/water.qoi" };
17 static int debugview
= 0;
18 static int sv_debugcam
= 0;
19 static int lightedit
= 0;
20 static int sv_scene
= 0;
23 //#define SR_NETWORKED
25 /* uncomment this to run the game without any graphics being drawn */
26 //#define SR_NETWORK_TEST
36 #include "character.h"
38 #include "rigidbody.h"
45 #include "shaders/blit.h"
46 #include "shaders/standard.h"
47 #include "shaders/unlit.h"
49 #include "physics_test.h"
51 void vg_register(void)
53 shader_blit_register();
54 shader_standard_register();
55 shader_vblend_register();
56 shader_unlit_register();
64 static void init_other(void)
74 vg_tex2d
*texture_list
[] =
85 int main( int argc
, char *argv
[] )
87 vg_init( argc
, argv
, "Voyager Game Engine" );
90 static int playermodel( int argc
, char const *argv
[] )
92 if( argc
< 1 ) return 0;
94 glmesh old_mesh
= player
.mdl
.mesh
;
96 if( character_load( &player
.mdl
, argv
[0] ) )
97 mesh_free( &old_mesh
);
106 vg_convar_push( (struct vg_convar
){
109 .data_type
= k_convar_dtype_i32
,
110 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
114 vg_convar_push( (struct vg_convar
){
116 .data
= &walk_grid_iterations
,
117 .data_type
= k_convar_dtype_i32
,
118 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
122 vg_convar_push( (struct vg_convar
){
125 .data_type
= k_convar_dtype_f32
,
126 .opt_f32
= { .clamp
= 0 },
130 vg_convar_push( (struct vg_convar
){
133 .data_type
= k_convar_dtype_i32
,
134 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
138 vg_convar_push( (struct vg_convar
){
139 .name
= "walk_speed",
140 .data
= &k_walkspeed
,
141 .data_type
= k_convar_dtype_f32
,
142 .opt_f32
= { .clamp
= 0 },
146 vg_convar_push( (struct vg_convar
){
149 .data_type
= k_convar_dtype_f32
,
150 .opt_f32
= { .clamp
= 0 },
154 vg_convar_push( (struct vg_convar
){
156 .data
= &sv_debugcam
,
157 .data_type
= k_convar_dtype_i32
,
158 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
162 vg_convar_push( (struct vg_convar
){
165 .data_type
= k_convar_dtype_i32
,
166 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
170 vg_function_push( (struct vg_cmd
){
172 .function
= reset_player
175 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
180 * If we're in physics test mode we dont need to load anything else, this
181 * parameter is dev only. TODO: dev only cvars that don't ship with the game
182 * when building in release mode.
187 character_load( &player
.mdl
, "ch_default" );
188 character_init_ragdoll( &player
.mdl
);
192 reset_player( 1, (const char *[]){ "start" } );
193 rb_init( &player
.rb
);
199 physics_test_start();
207 vg_tex2d_free( texture_list
, vg_list_size(texture_list
) );
208 /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */
221 //traffic_visualize( world.traffic, world.traffic_count );
224 if( glfwGetKey( vg_window
, GLFW_KEY_J
))
226 v3_copy( player
.camera_pos
, world
.mr_ball
.co
);
229 else if( sv_scene
== 1 )
231 physics_test_update();
235 static void vg_framebuffer_resize( int w
, int h
)
242 static void draw_origin_axis(void)
244 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
245 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
246 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
249 static void render_main_game(void)
251 float speed
= freecam
? 0.0f
: v3_length( player
.rb
.v
);
252 v3f shake
= { vg_randf()-0.5f
, vg_randf()-0.5f
, vg_randf()-0.5f
};
253 v3_muls( shake
, speed
*0.01f
, shake
);
256 m4x3_expand( player
.camera_inverse
, world_4x4
);
258 gpipeline
.fov
= freecam
? 60.0f
: 135.0f
; /* 120 */
259 m4x4_projection( vg_pv
, gpipeline
.fov
,
260 (float)vg_window_x
/ (float)vg_window_y
,
263 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
265 glEnable( GL_DEPTH_TEST
);
271 render_world( vg_pv
, player
.camera
);
272 render_water_texture( player
.camera
);
274 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
275 render_water_surface( vg_pv
, player
.camera
);
277 vg_tex2d_bind( &tex_water
, 1 ); /*TODO: ?*/
278 render_world_gates( vg_pv
, player
.camera
);
280 /* Copy the RGB of what we have into the background buffer */
281 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
282 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
283 glBlitFramebuffer( 0,0, vg_window_x
, vg_window_y
,
284 0,0, vg_window_x
, vg_window_y
,
288 /* Clear out the colour buffer, but keep depth */
289 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
290 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
292 if( !player
.is_dead
)
293 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
295 glClear( GL_COLOR_BUFFER_BIT
);
297 if( !player
.is_dead
)
299 m4x4_projection( vg_pv
, gpipeline
.fov
,
300 (float)vg_window_x
/ (float)vg_window_y
,
302 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
306 /* Draw back in the background
308 * TODO: need to disable alpha write in the terrain shader so this works
312 glDisable(GL_DEPTH_TEST
);
313 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
314 glBlendEquation(GL_FUNC_ADD
);
317 shader_blit_uTexMain( 0 );
318 glActiveTexture(GL_TEXTURE0
);
319 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
325 glDisable( GL_DEPTH_TEST
);
326 vg_lines_drawall( (float *)vg_pv
);
327 glViewport( 0,0, vg_window_x
, vg_window_y
);
332 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
333 glViewport( 0,0, vg_window_x
, vg_window_y
);
335 glDisable( GL_DEPTH_TEST
);
336 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
337 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
339 #ifndef SR_NETWORK_TEST
346 else if( sv_scene
== 1 )
348 physics_test_render();
353 static void run_light_widget( struct light_widget
*lw
)
355 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
357 ui_checkbox( &ui_global_ctx
, &c1
);
361 struct ui_slider_vector
362 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
363 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
365 ui_slider_vector( &ui_global_ctx
, &colour
);
366 ui_global_ctx
.cursor
[1] += 4;
367 ui_slider_vector( &ui_global_ctx
, &dir
);
371 static void run_debug_info(void)
375 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.rb
.v
) );
376 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
378 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
379 player
.a
[0], player
.a
[1], player
.a
[2] );
380 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
382 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
383 player
.rb
.co
[0], player
.rb
.co
[1], player
.rb
.co
[2] );
384 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
386 if( vg_gamepad_ready
)
388 for( int i
=0; i
<6; i
++ )
390 snprintf( buf
, 40, "%.2f", vg_gamepad
.axes
[i
] );
391 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
396 gui_text( (ui_px
[2]){ 0, 60 },
397 "Gamepad not ready", 1, k_text_align_left
);
405 ui_global_ctx
.cursor
[0] = 10;
406 ui_global_ctx
.cursor
[1] = 10;
407 ui_global_ctx
.cursor
[2] = 200;
408 ui_global_ctx
.cursor
[3] = 20;
410 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
411 struct ui_slider_vector
412 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
415 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
416 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
418 for( int i
=0; i
<3; i
++ )
419 run_light_widget( &gpipeline
.widgets
[i
] );
421 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
422 ui_global_ctx
.cursor
[1] += 16;
423 ui_slider_vector( &ui_global_ctx
, &s5
);
425 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
426 ui_global_ctx
.cursor
[1] += 16;
427 ui_slider( &ui_global_ctx
, &s8
);
428 ui_slider( &ui_global_ctx
, &s9
);
430 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
431 ui_global_ctx
.cursor
[1] += 16;
432 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
433 ui_checkbox( &ui_global_ctx
, &c1
);
435 render_update_lighting_ub();
438 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
439 render_world_routes_ui();
440 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
443 static double last_b_press
= 0.0;
445 double localtime
= vg_time
- last_b_press
;
447 world_routes_ui_updatetime( 0, localtime
);
448 world_routes_ui_draw( 0, (v4f
){ 1.0f
,0.0f
,1.0f
,1.0f
}, 9.0f
);
450 if( glfwGetKey(vg_window
,GLFW_KEY_B
) )
451 world_routes_ui_notch( 0, localtime
);
453 if( vg_time
-last_b_press
> 1.0 )
454 if( glfwGetKey(vg_window
,GLFW_KEY_N
) )
456 last_b_press
= vg_time
;
457 world_routes_ui_newseg( 0 );
460 static double last_m_press
;
461 if( vg_time
-last_m_press
> 1.0 )
462 if( glfwGetKey( vg_window
, GLFW_KEY_M
) )
464 last_m_press
= vg_time
;
466 vg_info( "start: %u\n",world
.routes
.routes
[0].ui
.segment_count
);
467 for( int i
=0; i
<world
.routes
.routes
[0].ui
.segment_count
; i
++ )
468 world_routes_ui_popfirst(0);
470 vg_info( "new: %u\n",world
.routes
.routes
[0].ui
.segment_count
);