2 * =============================================================================
4 * Copyright . . . -----, ,----- ,---. .---.
5 * 2021-2022 |\ /| | / | | | | /|
6 * | \ / | +-- / +----- +---' | / |
7 * | \ / | | / | | \ | / |
8 * | \/ | | / | | \ | / |
9 * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
11 * =============================================================================
13 * register: shader register & init scheduling
14 * init: initialization
32 int main( int argc
, char *argv
[] )
34 vg_enter( argc
, argv
, "Voyager Game Engine" );
37 static void highscores_save_at_exit(void*_
)
39 highscores_serialize_all();
45 vg_convar_push( (struct vg_convar
){
48 .data_type
= k_convar_dtype_i32
,
49 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
53 vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
54 vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" );
55 vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
56 vg_info(" | \\ / | | / | | \\ | / | \n" );
57 vg_info(" | \\/ | | / | | \\ | / | \n" );
58 vg_info(" ' ' '--' [] '----- '----- ' ' '---' "
61 highscores_init( 2000, 50 );
62 vg_loader_highwater( NULL
, highscores_save_at_exit
, NULL
);
67 vg_loader_highwater( NULL
, steam_end
, NULL
);
69 vg_loader_highwater( network_init
, network_end
, NULL
);
74 vg_loader_highwater( render_init
, render_free
, NULL
);
75 vg_loader_highwater( world_init
, world_free
, NULL
);
76 vg_loader_highwater( player_init
, NULL
, NULL
);
78 if( !vg_bake_shaders() )
79 vg_fatal_exit_loop( "Did not load all shaders" );
81 vg_loader_highwater( audio_init
, audio_free
, NULL
);
85 vg_console_load_autos();
88 static void vg_start(void)
90 player_load_model( "ch_new" );
91 reset_player( 1, (const char *[]){ "start" } );
94 static void draw_origin_axis(void)
96 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
97 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
98 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
101 void vg_update( int loaded
)
110 world_update( player
.phys
.rb
.co
);
114 static void vg_update_fixed( int loaded
)
118 player_update_fixed();
122 static void vg_update_post( int loaded
)
126 player_update_post();
130 static void vg_framebuffer_resize( int w
, int h
)
137 static void render_main_game(void)
140 m4x3_expand( player
.camera_inverse
, world_4x4
);
142 gpipeline
.fov
= freecam
? 60.0f
: 125.0f
; /* 120 */
143 m4x4_projection( vg
.pv
, gpipeline
.fov
,
144 (float)vg
.window_x
/ (float)vg
.window_y
,
147 m4x4_mul( vg
.pv
, world_4x4
, vg
.pv
);
148 glEnable( GL_DEPTH_TEST
);
154 int draw_solid
= player
.is_dead
| freecam
;
156 render_world( vg
.pv
, player
.camera
);
159 render_water_texture( player
.camera
);
161 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
162 render_water_surface( vg
.pv
, player
.camera
);
164 render_world_gates( vg
.pv
, player
.phys
.rb
.co
, player
.camera
);
166 /* Copy the RGB of what we have into the background buffer */
167 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
168 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
169 glBlitFramebuffer( 0,0, vg
.window_x
, vg
.window_y
,
170 0,0, vg
.window_x
, vg
.window_y
,
174 /* Clear out the colour buffer, but keep depth */
175 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
176 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
178 if( !player
.is_dead
)
179 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
181 glClear( GL_COLOR_BUFFER_BIT
);
185 m4x4_projection( vg
.pv
, gpipeline
.fov
,
186 (float)vg
.window_x
/ (float)vg
.window_y
,
188 m4x4_mul( vg
.pv
, world_4x4
, vg
.pv
);
192 /* Draw back in the background
194 * TODO: need to disable alpha write in the terrain shader so this works
198 glDisable(GL_DEPTH_TEST
);
199 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
200 glBlendEquation(GL_FUNC_ADD
);
203 shader_blit_uTexMain( 0 );
204 glActiveTexture(GL_TEXTURE0
);
205 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
212 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
213 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
214 glDisable( GL_DEPTH_TEST
);
216 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
217 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
224 glDisable( GL_DEPTH_TEST
);
225 vg_lines_drawall( (float *)vg
.pv
);
226 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
234 ui_global_ctx
.cursor
[0] = 10;
235 ui_global_ctx
.cursor
[1] = 10;
236 ui_global_ctx
.cursor
[2] = 200;
237 ui_global_ctx
.cursor
[3] = 20;
239 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
240 struct ui_slider_vector
241 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
244 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
245 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
247 for( int i
=0; i
<3; i
++ )
248 run_light_widget( &gpipeline
.widgets
[i
] );
250 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
251 ui_global_ctx
.cursor
[1] += 16;
252 ui_slider_vector( &ui_global_ctx
, &s5
);
254 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
255 ui_global_ctx
.cursor
[1] += 16;
256 ui_slider( &ui_global_ctx
, &s8
);
257 ui_slider( &ui_global_ctx
, &s9
);
259 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
260 ui_global_ctx
.cursor
[1] += 16;
261 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
262 ui_checkbox( &ui_global_ctx
, &c1
);
264 render_update_lighting_ub();
268 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
271 render_world_routes_ui();
273 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
275 audio_debug_soundscapes();
279 static void run_light_widget( struct light_widget
*lw
)
281 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
283 ui_checkbox( &ui_global_ctx
, &c1
);
287 struct ui_slider_vector
288 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
289 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
291 ui_slider_vector( &ui_global_ctx
, &colour
);
292 ui_global_ctx
.cursor
[1] += 4;
293 ui_slider_vector( &ui_global_ctx
, &dir
);
298 static void run_debug_info(void)
302 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.phys
.rb
.v
) );
303 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
305 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
306 player
.phys
.a
[0], player
.phys
.a
[1], player
.phys
.a
[2] );
307 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
309 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
310 player
.phys
.rb
.co
[0], player
.phys
.rb
.co
[1], player
.phys
.rb
.co
[2] );
311 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
313 if( vg
.gamepad_ready
)
315 for( int i
=0; i
<6; i
++ )
317 snprintf( buf
, 40, "%.2f", vg
.gamepad
.axes
[i
] );
318 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
323 gui_text( (ui_px
[2]){ 0, 60 },
324 "Gamepad not ready", 1, k_text_align_left
);