-
- v3f lightDir = { 0.1f, 0.8f, 0.2f };
- v3_normalize( lightDir );
-
- character_load( &player.mdl, "ch_default" );
-
- /* temp */
- model *cement_model = vg_asset_read("models/cement_r1.mdl" );
- model_unpack( cement_model, &world.cement );
- free( cement_model );
-
- /* Setup scene */
- scene_init( &world.geo );
- scene_init( &world.detail );
- scene_init( &world.foliage );
-
- model *mworld = vg_asset_read( "models/free_dev.mdl" );
- model *mtest = vg_asset_read( "models/test.mdl" );
-
- model *msky = vg_asset_read( "models/skydome.mdl" );
- model_unpack( msky, &world.skydome );
- free( msky );
-
- scene_add_model( &world.geo, mworld, submodel_get( mworld, "terrain" ),
- (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f );
- scene_copy_slice( &world.geo, &world.terrain );
-
- scene_add_model( &world.geo, mworld, submodel_get( mworld, "terrain_rocks" ),
- (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f );
- scene_copy_slice( &world.geo, &world.terrain_rocks );
-
- submodel *ptree = submodel_get( mtest, "tree" ),
- *pt_groundcover[] =
- {
- submodel_get( mtest, "bush" ),
- submodel_get( mtest, "bush" ),
- submodel_get( mtest, "blubber" ),
- };
-
- /* Sprinkle some trees in the terrain areas */
- v3f range;
- v3_sub( world.geo.bbx[1], world.geo.bbx[0], range );
-
-#ifdef VG_RELEASE
- int const ktree_count = 8000,
- kfoliage_count = 200000;
-#else
- int const ktree_count = 200,
- kfoliage_count = 0;
-#endif
-
- for( int i=0; i<ktree_count; i++ )
- {
- v3f pos = { vg_randf(), 0.0f, vg_randf() },
- norm;
-
- v3_muladd( world.geo.bbx[0], pos, range, pos );
-
- if( sample_scene_height( &world.geo, pos, norm ) )
- {
- if( v3_dot( norm, (v3f){ 0.0f, 1.0f, 0.0f } ) > 0.9f )
- {
- scene_add_model( &world.foliage, mtest, ptree,
- pos, vg_randf() * VG_TAUf, vg_randf() * 0.5f + 0.5f );
- }
- }
- }
-
- for( int i=0; i<kfoliage_count; i++ )
- {
- v3f pos = { vg_randf(), 0.0f, vg_randf() },
- norm;
-
- v3_muladd( world.geo.bbx[0], pos, range, pos );
-
- if( sample_scene_height( &world.geo, pos, norm ) )
- {
- if( v3_dot( norm, (v3f){ 0.0f, 1.0f, 0.0f } ) > 0.7f )
- {
- scene_add_model( &world.foliage, mtest,
- pt_groundcover[rand()%vg_list_size(pt_groundcover)],
- pos, vg_randf() * VG_TAUf, vg_randf() * 0.5f + 0.5f );
- }
- }
- }
-
- scene_add_model( &world.geo, mworld, submodel_get( mworld, "road" ),
- (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f );
- scene_copy_slice( &world.geo, &world.terrain_road );
-
- scene_add_model( &world.detail, mworld, submodel_get( mworld, "art" ),
- (v3f){0.0f,0.0f,0.0f}, 0.0f, 1.0f );
-
- free( mtest );
- free( mworld );
-
- scene_compute_occlusion( &world.foliage );
-
- scene_upload( &world.foliage );
- scene_upload( &world.geo );
- scene_upload( &world.detail );
-
- reset_player( 0, NULL );
- player_transform_update();
-
- /* Create framebuffers */
- glGenFramebuffers( 1, &render.fb_background );
- glBindFramebuffer( GL_FRAMEBUFFER, render.fb_background );
-
- glGenTextures( 1, &render.rgb_background );
- glBindTexture( GL_TEXTURE_2D, render.rgb_background );
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, vg_window_x, vg_window_y,
- 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
- GL_TEXTURE_2D,
- render.rgb_background, 0);
-
- {
- float quad[] = { 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f,
- 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f };
-
- glGenVertexArrays( 1, &render.fsquad.vao );
- glGenBuffers( 1, &render.fsquad.vbo );
- glGenBuffers( 1, &render.fsquad.ebo );
- glBindVertexArray( render.fsquad.vao );
- glBindBuffer( GL_ARRAY_BUFFER, render.fsquad.vbo );
- glBufferData( GL_ARRAY_BUFFER, sizeof(quad), quad, GL_STATIC_DRAW );
- glBindVertexArray( render.fsquad.vao );
- glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE,
- sizeof(float)*2, (void*)0 );
- glEnableVertexAttribArray( 0 );
- VG_CHECK_GL();
- }
-}
-
-static float ktimestep = 1.0f/60.0f;
-
-static void player_freecam(void)
-{
- m4x3f cam_rot;
- m4x3_identity( cam_rot );
- m4x3_rotate_y( cam_rot, -player.look_dir[0] );
- m4x3_rotate_x( cam_rot, -player.look_dir[1] );
-
- v3f lookdir = { 0.0f, 0.0f, -1.0f },
- sidedir = { 1.0f, 0.0f, 0.0f };
-
- m4x3_mulv( cam_rot, lookdir, lookdir );
- m4x3_mulv( cam_rot, sidedir, sidedir );
-
- float movespeed = 5.0f;
- static v2f mouse_last,
- view_vel = { 0.0f, 0.0f };