def609d6c915b063db19fba3a135ea68c810261f
4 vg_tex2d tex_norwey
= { .path
= "textures/norway_foliage.qoi" };
5 vg_tex2d tex_grid
= { .path
= "textures/grid.qoi" };
6 vg_tex2d tex_sky
= { .path
= "textures/sky.qoi" };
7 vg_tex2d tex_gradients
= { .path
= "textures/gradients.qoi",
8 .flags
= VG_TEXTURE_CLAMP
};
9 vg_tex2d tex_cement
= { .path
= "textures/cement512.qoi" };
10 vg_tex2d tex_water
= { .path
= "textures/water.qoi" };
13 static int debugview
= 0;
14 static int sv_debugcam
= 0;
21 #include "character.h"
23 #include "rigidbody.h"
30 #include "shaders/blit.h"
31 #include "shaders/standard.h"
32 #include "shaders/unlit.h"
34 void vg_register(void)
36 shader_blit_register();
37 shader_standard_register();
38 shader_unlit_register();
46 vg_tex2d
*texture_list
[] =
57 int main( int argc
, char *argv
[] )
59 vg_init( argc
, argv
, "Voyager Game Engine" );
62 static int playermodel( int argc
, char const *argv
[] )
64 if( argc
< 1 ) return 0;
66 glmesh old_mesh
= player
.mdl
.mesh
;
68 if( character_load( &player
.mdl
, argv
[0] ) )
69 mesh_free( &old_mesh
);
76 vg_convar_push( (struct vg_convar
){
79 .data_type
= k_convar_dtype_i32
,
80 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
84 vg_convar_push( (struct vg_convar
){
86 .data
= &walk_grid_iterations
,
87 .data_type
= k_convar_dtype_i32
,
88 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
92 vg_convar_push( (struct vg_convar
){
95 .data_type
= k_convar_dtype_f32
,
96 .opt_f32
= { .clamp
= 0 },
100 vg_convar_push( (struct vg_convar
){
102 .data
= &sv_debugcam
,
103 .data_type
= k_convar_dtype_i32
,
104 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
108 vg_convar_push( (struct vg_convar
){
111 .data_type
= k_convar_dtype_i32
,
112 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
116 vg_function_push( (struct vg_cmd
){
118 .function
= reset_player
121 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
128 character_load( &player
.mdl
, "ch_default" );
129 character_init_ragdoll( &player
.mdl
);
133 reset_player( 1, (const char *[]){ "tutorial" } );
134 player_transform_update();
139 vg_tex2d_free( texture_list
, vg_list_size(texture_list
) );
147 static void vg_framebuffer_resize( int w
, int h
)
156 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
157 glViewport( 0,0, vg_window_x
, vg_window_y
);
159 glDisable( GL_DEPTH_TEST
);
160 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
161 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
163 float speed
= freecam
? 0.0f
: v3_length( player
.v
);
164 v3f shake
= { vg_randf()-0.5f
, vg_randf()-0.5f
, vg_randf()-0.5f
};
165 v3_muls( shake
, speed
*0.01f
, shake
);
168 m4x3_expand( player
.camera_inverse
, world_4x4
);
170 gpipeline
.fov
= freecam
? 60.0f
: 120.0f
; /* 120 */
171 m4x4_projection( vg_pv
, gpipeline
.fov
,
172 (float)vg_window_x
/ (float)vg_window_y
,
175 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
177 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
178 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
179 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
181 glEnable( GL_DEPTH_TEST
);
187 render_world( vg_pv
, player
.camera
);
188 render_water_texture( player
.camera
);
190 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
191 render_water_surface( vg_pv
, player
.camera
);
193 vg_tex2d_bind( &tex_water
, 1 );
195 for( int i
=0; i
<world
.gate_count
; i
++ )
197 render_gate( &world
.gates
[i
], player
.camera
);
201 /* Copy the RGB of what we have into the background buffer */
202 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
203 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
204 glBlitFramebuffer( 0,0, vg_window_x
, vg_window_y
,
205 0,0, vg_window_x
, vg_window_y
,
209 /* Clear out the colour buffer, but keep depth */
210 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
211 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
213 if( !player
.is_dead
)
214 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
216 glClear( GL_COLOR_BUFFER_BIT
);
220 /* Draw back in the background
222 * TODO: need to disable alpha write in the terrain shader so this works
226 glDisable(GL_DEPTH_TEST
);
227 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
228 glBlendEquation(GL_FUNC_ADD
);
231 shader_blit_uTexMain( 0 );
232 glActiveTexture(GL_TEXTURE0
);
233 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
239 glDisable( GL_DEPTH_TEST
);
240 vg_lines_drawall( (float *)vg_pv
);
241 glViewport( 0,0, vg_window_x
, vg_window_y
);
248 snprintf( buf
, 20, "%.2fm/s", v3_length( player
.v
) );
249 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
251 snprintf( buf
, 20, "%.2f %.2f %.2f m/s",
252 player
.a
[0], player
.a
[1], player
.a
[2] );
253 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
255 snprintf( buf
, 20, "pos %.2f %.2f %.2f",
256 player
.co
[0], player
.co
[1], player
.co
[2] );
257 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
259 if( vg_gamepad_ready
)
261 for( int i
=0; i
<6; i
++ )
263 snprintf( buf
, 20, "%.2f", vg_gamepad
.axes
[i
] );
264 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
269 gui_text( (ui_px
[2]){ 0, 60 },
270 "Gamepad not ready", 1, k_text_align_left
);