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;
26 #include "character.h"
28 #include "rigidbody.h"
35 #include "shaders/blit.h"
36 #include "shaders/standard.h"
37 #include "shaders/unlit.h"
39 void vg_register(void)
41 shader_blit_register();
42 shader_standard_register();
43 shader_unlit_register();
51 static void init_other(void)
60 vg_tex2d
*texture_list
[] =
71 int main( int argc
, char *argv
[] )
73 vg_init( argc
, argv
, "Voyager Game Engine" );
76 static int playermodel( int argc
, char const *argv
[] )
78 if( argc
< 1 ) return 0;
80 glmesh old_mesh
= player
.mdl
.mesh
;
82 if( character_load( &player
.mdl
, argv
[0] ) )
83 mesh_free( &old_mesh
);
90 vg_convar_push( (struct vg_convar
){
93 .data_type
= k_convar_dtype_i32
,
94 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
98 vg_convar_push( (struct vg_convar
){
100 .data
= &walk_grid_iterations
,
101 .data_type
= k_convar_dtype_i32
,
102 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
106 vg_convar_push( (struct vg_convar
){
107 .name
= "walk_speed",
108 .data
= &k_walkspeed
,
109 .data_type
= k_convar_dtype_f32
,
110 .opt_f32
= { .clamp
= 0 },
114 vg_convar_push( (struct vg_convar
){
116 .data
= &sv_debugcam
,
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_i32
,
126 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
130 vg_function_push( (struct vg_cmd
){
132 .function
= reset_player
135 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
139 character_load( &player
.mdl
, "ch_default" );
140 character_init_ragdoll( &player
.mdl
);
144 reset_player( 1, (const char *[]){ "tutorial" } );
145 player_transform_update();
150 vg_tex2d_free( texture_list
, vg_list_size(texture_list
) );
158 static void vg_framebuffer_resize( int w
, int h
)
167 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
168 glViewport( 0,0, vg_window_x
, vg_window_y
);
170 glDisable( GL_DEPTH_TEST
);
171 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
172 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
174 float speed
= freecam
? 0.0f
: v3_length( player
.v
);
175 v3f shake
= { vg_randf()-0.5f
, vg_randf()-0.5f
, vg_randf()-0.5f
};
176 v3_muls( shake
, speed
*0.01f
, shake
);
179 m4x3_expand( player
.camera_inverse
, world_4x4
);
181 gpipeline
.fov
= freecam
? 60.0f
: 135.0f
; /* 120 */
182 m4x4_projection( vg_pv
, gpipeline
.fov
,
183 (float)vg_window_x
/ (float)vg_window_y
,
186 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
188 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
189 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
190 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
192 glEnable( GL_DEPTH_TEST
);
198 render_world( vg_pv
, player
.camera
);
199 render_water_texture( player
.camera
);
201 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
202 render_water_surface( vg_pv
, player
.camera
);
204 vg_tex2d_bind( &tex_water
, 1 );
206 for( int i
=0; i
<world
.gate_count
; i
++ )
208 render_gate( &world
.gates
[i
], player
.camera
);
212 /* Copy the RGB of what we have into the background buffer */
213 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
214 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
215 glBlitFramebuffer( 0,0, vg_window_x
, vg_window_y
,
216 0,0, vg_window_x
, vg_window_y
,
220 /* Clear out the colour buffer, but keep depth */
221 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
222 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
224 if( !player
.is_dead
)
225 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
227 glClear( GL_COLOR_BUFFER_BIT
);
231 /* Draw back in the background
233 * TODO: need to disable alpha write in the terrain shader so this works
237 glDisable(GL_DEPTH_TEST
);
238 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
239 glBlendEquation(GL_FUNC_ADD
);
242 shader_blit_uTexMain( 0 );
243 glActiveTexture(GL_TEXTURE0
);
244 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
250 glDisable( GL_DEPTH_TEST
);
251 vg_lines_drawall( (float *)vg_pv
);
252 glViewport( 0,0, vg_window_x
, vg_window_y
);
259 snprintf( buf
, 20, "%.2fm/s", v3_length( player
.v
) );
260 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
262 snprintf( buf
, 20, "%.2f %.2f %.2f m/s",
263 player
.a
[0], player
.a
[1], player
.a
[2] );
264 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
266 snprintf( buf
, 20, "pos %.2f %.2f %.2f",
267 player
.co
[0], player
.co
[1], player
.co
[2] );
268 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
270 if( vg_gamepad_ready
)
272 for( int i
=0; i
<6; i
++ )
274 snprintf( buf
, 20, "%.2f", vg_gamepad
.axes
[i
] );
275 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
280 gui_text( (ui_px
[2]){ 0, 60 },
281 "Gamepad not ready", 1, k_text_align_left
);