void templateAppInit(int width, int height)
{
    glViewport(0.0f, 0.0f, width, height);
    glGetIntegerv(GL_VIEWPORT, viewport_matrix);
    GFX_start();
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJ_optimize_mesh(obj, i, 128);
	OBJ_build_mesh2(obj, i);
	OBJ_free_mesh_vertex_data(obj, i);
	++i;
    }
    i = 0;
    while (i != obj->n_texture) {
	OBJ_build_texture(obj, i, obj->texture_path, TEXTURE_MIPMAP | TEXTURE_16_BITS, TEXTURE_FILTER_2X, 0.0f);
	++i;
    }
    i = 0;
    while (i != obj->n_program) {
	OBJ_build_program(obj, i, program_bind_attrib_location, program_draw, 1, obj->program_path);
	++i;
    }
    i = 0;
    while (i != obj->n_objmaterial) {
	OBJ_build_material(obj, i, NULL);
	++i;
    }
    vec4 color = { 1.0f, 1.0f, 1.0f, 1.0f };
    vec3 position = { 7.5f, 0.0f, 6.0f };
    light = LIGHT_create_spot((char *)"spot", &color, &position, 0.0f, 0.0f, 0.0f, 75.0f, 0.05f);
    OBJ_get_mesh(obj, (char *)"projector", 0)->visible = 0;
    glGetIntegerv(GL_FRAMEBUFFER_BINDING, &main_buffer);
    if (main_buffer == -1)
	main_buffer = 0;
    glGenFramebuffers(1, &shadowmap_buffer);
    glBindFramebuffer(GL_FRAMEBUFFER, shadowmap_buffer);
    glGenTextures(1, &depth_texture);
    glBindTexture(GL_TEXTURE_2D, depth_texture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowmap_width, shadowmap_height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, NULL);
    glBindTexture(GL_TEXTURE_2D, 0);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depth_texture, 0);
}
void templateAppInit(int width, int height)
{
    GFX_start();
    glViewport(0.0f, 0.0f, width, height);
    GFX_set_matrix_mode(PROJECTION_MATRIX);
    GFX_load_identity();
    GFX_set_perspective(80.0f, (float)width / (float)height, 1.0f, 100.0f, -90.0f);
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	if (strstr(obj->objmesh[i].name, "maze")) {
	    navigation = NAVIGATION_init((char *)"maze");
	    navigation->navigationconfiguration.agent_height = 2.0f;
	    navigation->navigationconfiguration.agent_radius = 0.4f;
	    if (NAVIGATION_build(navigation, obj, i)) {
		console_print("Navigation generated.\n");
	    } else {
		console_print("Unable to create the navigation mesh.");
	    }
	}
	OBJ_optimize_mesh(obj, i, 128);
	OBJ_build_mesh2(obj, i);
	OBJ_free_mesh_vertex_data(obj, i);
	++i;
    }
    init_physic_world();
    load_physic_world();
    player = OBJ_get_mesh(obj, "player", 0);
    player->btrigidbody->setAngularFactor(0.0f);
    maze = OBJ_get_mesh(obj, "maze", 0);
    distance = maze->radius * 2.0f;
    i = 0;
    while (i != obj->n_texture) {
	OBJ_build_texture(obj, i, obj->texture_path, TEXTURE_MIPMAP | TEXTURE_16_BITS, TEXTURE_FILTER_2X, 0.0f);
	++i;
    }
    i = 0;
    while (i != obj->n_objmaterial) {
	OBJ_build_material(obj, i, NULL);
	++i;
    }
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, 0, program_bind_attrib_location, NULL);
}
Ejemplo n.º 3
0
void load_game( void )
{
	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {
	
		if( strstr( obj->objmesh[ i ].name, "maze" ) ) {
		
			navigation = NAVIGATION_init( ( char * )"maze" );

			navigation->navigationconfiguration.agent_height = 2.0f;

			navigation->navigationconfiguration.agent_radius = 0.4f;

			if( NAVIGATION_build( navigation, obj, i ) )
			{ console_print( "Navigation generated.\n"); }

			else
			{ console_print( "Unable to create the navigation mesh." ); }
		}
	
		OBJ_optimize_mesh( obj, i, 128 );

		OBJ_build_mesh2( obj, i );
		
		OBJ_free_mesh_vertex_data( obj, i );

		++i;
	}
	
	
	init_physic_world();
	
	load_physic_world();

	dispatcher->setNearCallback( near_callback );

	enemy = OBJ_get_mesh( obj, "enemy", 0 );

	enemy->btrigidbody->setAngularFactor( 0.0f );

	navigationpathdata_player.path_point_count =
	navigationpathdata_enemy.path_point_count  = 0;

	player_next_point =
	enemy_next_point  = -1;	


	player = OBJ_get_mesh( obj, "player", 0 );

	player->btrigidbody->setAngularFactor( 0.0f );

	maze = OBJ_get_mesh( obj, "maze", 0 );
	
	distance = maze->radius * 2.0f;


	i = 0;
	while( i != obj->n_texture ) { 

		OBJ_build_texture( obj,
						   i,
						   obj->texture_path,
						   TEXTURE_MIPMAP | TEXTURE_16_BITS,
						   TEXTURE_FILTER_2X,
						   0.0f );
		++i;
	}


	i = 0;
	while( i != obj->n_objmaterial ) { 

		OBJ_build_material( obj, i, NULL );
		
		++i;
	}	
	
	program = PROGRAM_create( ( char * )"default",
							  VERTEX_SHADER,
							  FRAGMENT_SHADER,
							  1,
							  0,
							  program_bind_attrib_location,
							  NULL );	
}
Ejemplo n.º 4
0
void templateAppInit( int width, int height ) {

	atexit( templateAppExit );

	GFX_start();

	glViewport( 0.0f, 0.0f, width, height );

	GFX_set_matrix_mode( PROJECTION_MATRIX );
	GFX_load_identity();
	
	
	GFX_set_perspective( 80.0f,
						 ( float )width / ( float )height,
						 1.0f,
						 100.0f,
						 -90.0f );
						 

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {
	
		OBJ_optimize_mesh( obj, i, 128 );

		/* OBJ_build_mesh2 is another version of the OBJ_build_mesh that do not 
		   use VAO (only pure glDraw calls), at the time of writing this book mixing
		   direct rendering using glDraw commands (as you will do in this chapter) with
		   VAO cause issues on some Android drivers. */
		OBJ_build_mesh2( obj, i );
		
		OBJ_free_mesh_vertex_data( obj, i );

		++i;
	}
	
	
	init_physic_world();
	
	load_physic_world();
	

	i = 0;
	while( i != obj->n_texture ) { 

		OBJ_build_texture( obj,
						   i,
						   obj->texture_path,
						   TEXTURE_MIPMAP | TEXTURE_16_BITS,
						   TEXTURE_FILTER_2X,
						   0.0f );
		++i;
	}


	i = 0;
	while( i != obj->n_objmaterial ) { 

		OBJ_build_material( obj, i, NULL );
		
		++i;
	}	
	
	program = PROGRAM_create( ( char * )"default",
							  VERTEX_SHADER,
							  FRAGMENT_SHADER,
							  1,
							  0,
							  program_bind_attrib_location,
							  NULL );
}