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, 0.1f, 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_mesh(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_objmaterial) {
	OBJ_build_material(obj, i, NULL);
	++i;
    }
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, 0, program_bind_attrib_location, NULL);
    PROGRAM_draw(program);
    glUniform1i(PROGRAM_get_uniform_location(program, (char *)"DIFFUSE"), 1);
}
void templateAppInit(int width, int height)
{
    GFX_start();
    glViewport(0.0f, 0.0f, width, height);
    glGetIntegerv(GL_VIEWPORT, viewport_matrix);
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJ_optimize_mesh(obj, i, 128);
	OBJ_build_mesh(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;
    }
}
Exemple #3
0
void load_game( void )
{
	init_physic_world();
	
	gContactAddedCallback = contact_added_callback;

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {
		
		OBJMESH *objmesh = &obj->objmesh[ i ];
		
		OBJ_optimize_mesh( obj, i, 128 );
		
		OBJ_build_mesh( 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;
	}

	program = PROGRAM_create( ( char * )"default",
							  VERTEX_SHADER,
							  FRAGMENT_SHADER,
							  1,
							  0,
							  program_bind_attrib_location,
							  NULL );

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

		OBJ_build_material( obj, i, NULL );
		
		++i;
	}	

	PROGRAM_draw( program );
	
	glUniform1i( PROGRAM_get_uniform_location( program, ( char * )"DIFFUSE" ), 1 );
}
Exemple #4
0
void templateAppInit( int width, int height ) {

	atexit( templateAppExit );

	GFX_start();
	
	init_physic_world();
	
	gContactAddedCallback = contact_added_callback;

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

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

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {

		OBJ_build_mesh( obj, i );
		
		OBJMESH *objmesh = &obj->objmesh[ i ];
				
		if( !strcmp( objmesh->name, "Cube" ) )
		{
			objmesh->rotation.x =
			objmesh->rotation.y =
			objmesh->rotation.z = 35.0f;
			
			add_rigid_body( objmesh, 1.0f );
		}

		else add_rigid_body( objmesh, 0.0f );		

		OBJ_free_mesh_vertex_data( obj, i ); 

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

	PROGRAM_draw( program );
}
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(45.0f, (float)width / (float)height, 0.1f, 100.0f, 0.0f);
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, DEBUG_SHADERS, NULL, program_draw_callback);
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned char *vertex_array = NULL, *vertex_start = NULL;
    unsigned int i = 0, index = 0, stride = 0, size = 0;
    objmesh = &obj->objmesh[0];
    size = objmesh->n_objvertexdata * sizeof(vec3) * sizeof(vec3) * sizeof(vec2);
    vertex_array = (unsigned char *)malloc(size);
    vertex_start = vertex_array;
    while (i != objmesh->n_objvertexdata) {
	index = objmesh->objvertexdata[i].vertex_index;
	memcpy(vertex_array, &obj->indexed_vertex[index], sizeof(vec3));
	vertex_array += sizeof(vec3);
	memcpy(vertex_array, &obj->indexed_normal[index], sizeof(vec3));
	vertex_array += sizeof(vec3);
	memcpy(vertex_array, &obj->indexed_uv[objmesh->objvertexdata[i].uv_index], sizeof(vec2));
	vertex_array += sizeof(vec2);
	++i;
    }
    glGenBuffers(1, &objmesh->vbo);
    glBindBuffer(GL_ARRAY_BUFFER, objmesh->vbo);
    glBufferData(GL_ARRAY_BUFFER, size, vertex_start, GL_STATIC_DRAW);
    free(vertex_start);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glGenBuffers(1, &objmesh->objtrianglelist[0].vbo);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, objmesh->objtrianglelist[0].vbo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, objmesh->objtrianglelist[0].n_indice_array * sizeof(unsigned short), objmesh->objtrianglelist[0].indice_array, GL_STATIC_DRAW);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
    unsigned char attribute;
    stride = sizeof(vec3) + sizeof(vec3) + sizeof(vec2);
    glGenVertexArraysOES(1, &objmesh->vao);
    glBindVertexArrayOES(objmesh->vao);
    glBindBuffer(GL_ARRAY_BUFFER, objmesh->vbo);
    attribute = PROGRAM_get_vertex_attrib_location(program, (char *)"POSITION");
    glEnableVertexAttribArray(attribute);
    glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, stride, (void *)NULL);
    attribute = PROGRAM_get_vertex_attrib_location(program, (char *)"NORMAL");
    glEnableVertexAttribArray(attribute);
    glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(sizeof(vec3)));
    attribute = PROGRAM_get_vertex_attrib_location(program, (char *)"TEXCOORD0");
    glEnableVertexAttribArray(attribute);
    glVertexAttribPointer(attribute, 2, GL_FLOAT, GL_FALSE, stride, BUFFER_OFFSET(sizeof(vec3) + sizeof(vec3)));
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, objmesh->objtrianglelist[0].vbo);
    glBindVertexArrayOES(0);
    texture = TEXTURE_create(obj->objmaterial[0].map_diffuse, obj->objmaterial[0].map_diffuse, 1, TEXTURE_MIPMAP, TEXTURE_FILTER_2X, 0.0f);
}
void load_game(void)
{
    init_physic_world();
    gContactAddedCallback = contact_added_callback;
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJMESH *objmesh = &obj->objmesh[i];
	OBJ_optimize_mesh(obj, i, 128);
	OBJ_build_mesh(obj, i);
	if (strstr(objmesh->name, "momo"))
	    add_rigid_body(objmesh, SPHERE, 2.0f, 0);
	else if (strstr(objmesh->name, "barrel"))
	    add_rigid_body(objmesh, CYLINDER, 1.0f, 0);
	else if (strstr(objmesh->name, "plank"))
	    add_rigid_body(objmesh, BOX, 1.0f, 0);
	else if (strstr(objmesh->name, "ground"))
	    add_rigid_body(objmesh, BOX, 0.0f, 0);
	else if (strstr(objmesh->name, "steel"))
	    add_rigid_body(objmesh, CYLINDER, 0.0f, 0);
	else if (strstr(objmesh->name, "banana")) {
	    add_rigid_body(objmesh, SPHERE, 1.0f, 1);
	    objmesh->btrigidbody->setCollisionFlags(objmesh->btrigidbody->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
	    objmesh->btrigidbody->forceActivationState(ISLAND_SLEEPING);
	    ++banana;
	} else if (strstr(objmesh->name, "gameover")) {
	    objmesh->visible = 0;
	    gameover = objmesh;
	}
	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;
    }
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, 0, program_bind_attrib_location, NULL);
    i = 0;
    while (i != obj->n_objmaterial) {
	OBJ_build_material(obj, i, NULL);
	++i;
    }
    PROGRAM_draw(program);
    glUniform1i(PROGRAM_get_uniform_location(program, (char *)"DIFFUSE"), 1);
    momo_index = 0;
    center.x = eye.x = 3.5f;
    get_next_momo();
}
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(45.0f, (float)width / (float)height, 0.1f, 100.0f, -90.0f);
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJ_build_mesh(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_FILTER_2X, 0.0f);
	++i;
    }
    i = 0;
    while (i != obj->n_objmaterial) {
	MEMORY *fragment_shader = mopen((char *)"fragment.glsl", 1);
	MEMORY *vertex_shader = mopen((char *)"vertex.glsl", 1);
	OBJMATERIAL *objmaterial = &obj->objmaterial[i];
	OBJ_build_material(obj, i, NULL);
	if (objmaterial->dissolve == 1.0f)
	    minsert(fragment_shader, (char *)"#define SOLID_OBJECT\n", 0);
	else if (!objmaterial->dissolve)
	    minsert(fragment_shader, (char *)"#define ALPHA_TESTED_OBJECT\n", 0);
	else
	    minsert(fragment_shader, (char *)"#define TRANSPARENT_OBJECT\n", 0);
	if (objmaterial->illumination_model) {
	    minsert(vertex_shader, (char *)"#define LIGHTING_SHADER\n", 0);
	    minsert(fragment_shader, (char *)"#define LIGHTING_SHADER\n", 0);
	}
	objmaterial->program = PROGRAM_init(objmaterial->name);
	objmaterial->program->vertex_shader = SHADER_init((char *)"vertex", GL_VERTEX_SHADER);
	objmaterial->program->fragment_shader = SHADER_init((char *)"fragment", GL_FRAGMENT_SHADER);
	SHADER_compile(objmaterial->program->vertex_shader, (char *)vertex_shader->buffer, 1);
	SHADER_compile(objmaterial->program->fragment_shader, (char *)fragment_shader->buffer, 1);
	PROGRAM_set_bind_attrib_location_callback(objmaterial->program, program_bind_attrib_location);
	PROGRAM_link(objmaterial->program, 1);
	OBJ_set_draw_callback_material(obj, i, material_draw_callback);
	mclose(fragment_shader);
	mclose(vertex_shader);
	++i;
    }
}
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(45.0f, (float)width / (float)height, 0.1f, 100.0f, -90.0f);
    obj = OBJ_load(OBJ_FILE, 1);
    unsigned int i = 0;
    while (i != obj->n_objmesh) {
	OBJ_build_mesh(obj, i);
	OBJ_free_mesh_vertex_data(obj, i);
	++i;
    }
    program = PROGRAM_create((char *)"default", VERTEX_SHADER, FRAGMENT_SHADER, 1, 0, program_bind_attrib_location, NULL);
    PROGRAM_draw(program);
}
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);
}
Exemple #11
0
void load_level( void )
{
	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

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

		OBJ_build_mesh( obj, i );
		
		OBJ_free_mesh_vertex_data( obj, i );

		++i;
	}
	
	
	init_physic_world();
	
	load_physic_world();
	
	gContactAddedCallback = contact_added_callback;
	
	/* Get the mesh object name level_clear, which is the cylinder located
	 * in the middle of the level end target. */
   OBJMESH *level_clear = OBJ_get_mesh( obj, "level_clear", 0 );

   /* On top of the usual CF_CUSTOM_MATERIAL_CALLBACK collision flag,
   add CF_NO_CONTACT_RESPONSE. This collision flag makes your rigid
   body object act like a ghost, meaning that it will not respond to collision.
   This can be used to turn off the collision response of any rigid body,
    which is great for this typical scenario, where you only want the object to trigger the callback. */
   level_clear->btrigidbody->setCollisionFlags( level_clear->btrigidbody->getCollisionFlags()  |
												btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK |
												btCollisionObject::CF_NO_CONTACT_RESPONSE );

   /* Make the level_clear mesh invisible for rendering. */
   level_clear->visible = 0;

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

      OBJMESH *objmesh = &obj->objmesh[ i ];

      if( strstr( objmesh->name, "gem" ) ) { 

         objmesh->rotation.z = ( float )( random() % 360 );

         objmesh->btrigidbody->setCollisionFlags( objmesh->btrigidbody->getCollisionFlags() |
												  btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );
      }
	  
	  ++i;
   }	
	
	
	player = OBJ_get_mesh( obj, "player", 0 );
	
	player->btrigidbody->setFriction( 10.0f );
	
	memcpy( &eye, &player->location, sizeof( vec3 ) );
	
	
	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;
	}	

	

	font_small = FONT_init( ( char * )"foo.ttf" );

	FONT_load( font_small,
			   font_small->name,
			   1,
			   24.0f,
			   512,
			   512,
			   32,
			   96 );
			   

	font_big = FONT_init( ( char * )"foo.ttf" );

	FONT_load( font_big,
			   font_big->name,
			   1,
			   48.0f,
			   512,
			   512,
			   32,
			   96 );
			   
	/* Declare a memory structure that you will use (and reuse) to load each sound buffer. */
	MEMORY *memory = NULL;
	/* Reset the counter. */
	i = 0;
	while( i != 4 ) {
	
		switch( i ) { 
		
			case 0: {
				/* Load the red.ogg file. */
				memory = mopen( ( char * )"red.ogg", 1 );
				break;
			}
			case 1: {
				/* Load the green.ogg file. */
				memory = mopen( ( char * )"green.ogg", 1 );
				break;
			}
			case 2: {
				/* Load the blue.ogg file. */
				memory = mopen( ( char * )"blue.ogg", 1 );
				break;
			}
			case 3: {
				/* Load the yellow.ogg file. */
				memory = mopen( ( char * )"yellow.ogg", 1 );
				break;
			}
		}

		/* For the current gem buffer index, create a sound buffer using the content
		 * of the memory structure that we have loaded. */
		gems_soundbuffer[ i ] = SOUNDBUFFER_load( ( char * )"gem", memory );

		mclose( memory );
		
		/* Create a new sound source for the current index and link the current sound buffer. */
		gems_sound[ i ] =  SOUND_add( ( char * )"gem", gems_soundbuffer[ i ] );

		SOUND_set_volume( gems_sound[ i ], 1.0f );

		++i;
	}
	
	/* Temporary variable to contain the mesh pointer of the object that will be emitting the sound. */
	OBJMESH *objmesh = NULL;
	/* Load the water.ogg file in memory. */
	memory = mopen( ( char * )"water.ogg", 1 );

	water_soundbuffer = SOUNDBUFFER_load( ( char * )"water", memory );

	/* Free the memory , because the sound buffer is loaded as a static sound and the raw audio buffer has been transferred to the
	audio memory by the previous function call. */
	mclose( memory );

	/* Create the water sound source. */
	water_sound = SOUND_add( ( char * )"water", water_soundbuffer );

	/* Here comes the part of code where we are going to associate the
	sound source to the object. First, get the objmesh pointer for the water object. */
	objmesh = OBJ_get_mesh( obj, "water", 0 );

	/* Assign to the sound source the location of the mesh in 3D space and
	use the radius as the reference distance (how far the sound can be heard). */
	SOUND_set_location( water_sound,
						&objmesh->location,
						objmesh->radius );

	/* Set the volume of the water at 50%. */
	SOUND_set_volume( water_sound, 0.5f );

	SOUND_play( water_sound, 1 );

	//the same as above for the lava sound
	memory = mopen( ( char * )"lava.ogg", 1 );
	
	lava_soundbuffer = SOUNDBUFFER_load( ( char * )"lava", memory );
	
	mclose( memory );
	
	lava_sound = SOUND_add( ( char * )"lava", lava_soundbuffer );

	objmesh = OBJ_get_mesh( obj, "lava", 0 );

	SOUND_set_location( lava_sound,
						&objmesh->location, 
						objmesh->radius );
						
	SOUND_set_volume( lava_sound, 0.5f );

	SOUND_play( lava_sound, 1 );

	//finally for the toxic waste sound
	memory = mopen( ( char * )"toxic.ogg", 1 );
	
	toxic_soundbuffer = SOUNDBUFFER_load( ( char * )"toxic", memory );

	mclose( memory );

	toxic_sound = SOUND_add( ( char * )"toxic", toxic_soundbuffer );
	
	objmesh = OBJ_get_mesh( obj, "toxic", 0 );

	SOUND_set_location( toxic_sound,
						&objmesh->location, 
						objmesh->radius );
	
	SOUND_set_volume( toxic_sound, 0.5f );
	
	SOUND_play( toxic_sound, 1 );

	/* Load the background sound as a streamed buffer. */
	memory = mopen( ( char * )"background.ogg", 1 );

	background_soundbuffer = SOUNDBUFFER_load_stream( ( char * )"background", memory );

	background_sound = SOUND_add( ( char * )"background", background_soundbuffer );
	
	SOUND_set_volume( background_sound, 0.5f );
	/* Play the background sound in a loop. */
	SOUND_play( background_sound, 1 );

	//Start the decompression thread
	THREAD_play( thread );

}
Exemple #12
0
void load_level( void )
{
	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

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

		OBJ_build_mesh( obj, i );
		
		OBJ_free_mesh_vertex_data( obj, i );

		++i;
	}
	
	
	init_physic_world();
	
	load_physic_world();
	
	gContactAddedCallback = contact_added_callback;
	
	
   OBJMESH *level_clear = OBJ_get_mesh( obj, "level_clear", 0 );

   level_clear->btrigidbody->setCollisionFlags( level_clear->btrigidbody->getCollisionFlags()  |
												btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK |
												btCollisionObject::CF_NO_CONTACT_RESPONSE );
   level_clear->visible = 0;

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

      OBJMESH *objmesh = &obj->objmesh[ i ];

      if( strstr( objmesh->name, "gem" ) ) { 

         objmesh->rotation.z = ( float )( random() % 360 );

         objmesh->btrigidbody->setCollisionFlags( objmesh->btrigidbody->getCollisionFlags() |
												  btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK );
      }
	  
	  ++i;
   }	
	
	
	player = OBJ_get_mesh( obj, "player", 0 );
	
	player->btrigidbody->setFriction( 6.7f );
	

	memcpy( &eye, &player->location, sizeof( vec3 ) );
	
	
	i = 0;
	while( i != obj->n_texture ) { 

		OBJ_build_texture( obj,
						   i,
						   obj->texture_path,
						   TEXTURE_MIPMAP ,
						   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;
	}	

	

	font_small = FONT_init( ( char * )"foo.ttf" );

	FONT_load( font_small,
			   font_small->name,
			   1,
			   24.0f,
			   512,
			   512,
			   32,
			   96 );
			   

	font_big = FONT_init( ( char * )"foo.ttf" );

	FONT_load( font_big,
			   font_big->name,
			   1,
			   48.0f,
			   512,
			   512,
			   32,
			   96 );
			   

	MEMORY *memory = NULL;

	i = 0;
	while( i != 4 ) {
	
		switch( i ) { 
		
			case 0: {

				memory = mopen( ( char * )"red.ogg", 1 );
				break;
			}
			case 1: {

				memory = mopen( ( char * )"green.ogg", 1 );
				break;
			}
			case 2: {

				memory = mopen( ( char * )"blue.ogg", 1 );
				break;
			}
			case 3: {

				memory = mopen( ( char * )"yellow.ogg", 1 );
				break;
			}
		}

		gems_soundbuffer[ i ] = SOUNDBUFFER_load( ( char * )"gem", memory );

		mclose( memory );
		
		gems_sound[ i ] =  SOUND_add( ( char * )"gem", gems_soundbuffer[ i ] );

		SOUND_set_volume( gems_sound[ i ], 1.0f );

		++i;
	}
	

	OBJMESH *objmesh = NULL;
	
	memory = mopen( ( char * )"water.ogg", 1 );

	water_soundbuffer = 
	SOUNDBUFFER_load( ( char * )"water", memory );

	mclose( memory );

	water_sound = SOUND_add( ( char * )"water", water_soundbuffer );

	objmesh = OBJ_get_mesh( obj, "water", 0 );

	SOUND_set_location( water_sound,
	&objmesh->location, 
	objmesh->radius );

	SOUND_set_volume( water_sound, 0.5f );

	SOUND_play( water_sound, 1 );


	memory = mopen( ( char * )"lava.ogg", 1 );
	
	lava_soundbuffer = SOUNDBUFFER_load( ( char * )"lava", memory );
	
	mclose( memory );
	
	lava_sound = SOUND_add( ( char * )"lava", lava_soundbuffer );

	objmesh = OBJ_get_mesh( obj, "lava", 0 );

	SOUND_set_location( lava_sound,
						&objmesh->location, 
						objmesh->radius );
						
	SOUND_set_volume( lava_sound, 0.5f );

	SOUND_play( lava_sound, 1 );


	memory = mopen( ( char * )"toxic.ogg", 1 );
	
	toxic_soundbuffer = SOUNDBUFFER_load( ( char * )"toxic", memory );

	mclose( memory );

	toxic_sound = SOUND_add( ( char * )"toxic", toxic_soundbuffer );
	
	objmesh = OBJ_get_mesh( obj, "toxic", 0 );

	SOUND_set_location( toxic_sound,
						&objmesh->location, 
						objmesh->radius );
	
	SOUND_set_volume( toxic_sound, 0.5f );
	
	SOUND_play( toxic_sound, 1 );


	memory = mopen( ( char * )"background.ogg", 1 );

	background_soundbuffer = SOUNDBUFFER_load_stream( ( char * )"background", memory );

	background_sound = SOUND_add( ( char * )"background", background_soundbuffer );
	
	SOUND_set_volume( background_sound, 0.5f );

	SOUND_play( background_sound, 1 );

	THREAD_play( thread );
}
Exemple #13
0
void templateAppInit( int width, int height ) {

	atexit( templateAppExit );

	GFX_start();

	glViewport( 0.0f, 0.0f, width, height );
	
	glGetIntegerv( GL_VIEWPORT, viewport_matrix );

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

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

		OBJ_build_mesh( 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_3X,
						   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_point( ( char * )"point", &color, &position );
}
Exemple #14
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( 45.0f,
						 ( float )width / ( float )height,
						 0.1f,
						 100.0f,
						 0.0f );

	obj = OBJ_load( OBJ_FILE, 1 );

	unsigned int i = 0;

	while( i != obj->n_objmesh ) {

		console_print( "%s: %d: GL_TRIANGLES\n",
					   obj->objmesh[ i ].name,
					   obj->objmesh[ i ].objtrianglelist[ 0 ].n_indice_array );

		OBJ_optimize_mesh( obj, i, 128 );

		console_print( "%s: %d: GL_TRIANGLE_STRIP\n",
					   obj->objmesh[ i ].name,
					   obj->objmesh[ i ].objtrianglelist[ 0 ].n_indice_array );

		OBJ_build_mesh( 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_16_BITS_5551,
						   TEXTURE_FILTER_2X,
						   0.0f );
		++i;
	}	


	i = 0;

	while( i != obj->n_objmaterial ) {
	
		OBJ_build_material( obj,
							i,
							PROGRAM_create( ( char * )"default",
											VERTEX_SHADER,
											FRAGMENT_SHADER,
											1,
											1,
											program_bind_attrib_location,
											NULL ) );
		
		OBJ_set_draw_callback_material( obj, i, material_draw_callback );
		
		++i;
	}
}
Exemple #15
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 );
}
Exemple #16
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 );	
}
//获取obj文件,再获取该文件的网格
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( 45.0f,
						 ( float )width / ( float )height,
						 0.1f,
						 100.0f,
						 0.0f );
    //新建一个可自动加载、编译和链接着色器程序的着色器程序
	program = PROGRAM_create( ( char * )"default",
							  VERTEX_SHADER,
							  FRAGMENT_SHADER,
							  1,
							  DEBUG_SHADERS,
							  NULL,   //属性回调函数
							  program_draw_callback );   //绘制回调函数

    //加载obj文件
	obj = OBJ_load( OBJ_FILE, 1 );   


	unsigned char *vertex_array = NULL,
				  *vertex_start = NULL;

	unsigned int i	    = 0,
				 index  = 0,
				 stride = 0,
				 size   = 0;

    //获取结构指针中第一个网格的指针,
	objmesh = &obj->objmesh[ 0 ]; //里面包含多个obj文件的实体

    //计算顶点数据数组的总大小,以便可以分配为VBO构建GLES友好的顶点数据数组所需的内存大小
	size = objmesh->n_objvertexdata * sizeof( vec3 ) * sizeof( vec3 );

	vertex_array = ( unsigned char * ) malloc( size );
	vertex_start = vertex_array;

    //根据索引的顶点位置以及objmesh结构中包含的顶点法线构建顶点数据数组
	while( i != objmesh->n_objvertexdata ) { 

		index = objmesh->objvertexdata[ i ].vertex_index;

		memcpy( vertex_array,
				&obj->indexed_vertex[ index ],
				sizeof( vec3 ) );

		vertex_array += sizeof( vec3 );


		memcpy( vertex_array,
				&obj->indexed_normal[ index ],
				sizeof( vec3 ) );

		vertex_array += sizeof( vec3 );

		++i;
	}
    
    //请求驱动程序为VBO创建一个新的缓冲区索引,并使其处于活动状态
	glGenBuffers( 1, &objmesh->vbo ); 
	glBindBuffer( GL_ARRAY_BUFFER, objmesh->vbo );

    //将顶点数据数组从本地存储器转移到视频存储器
	glBufferData( GL_ARRAY_BUFFER,
				  size,
				  vertex_start,
				  GL_STATIC_DRAW );

	free( vertex_start );

	glBindBuffer( GL_ARRAY_BUFFER, 0 );

    //----------------------------------------------------
    
    //为第一个objmesh三角形列表创建一个新id,并使当前索引处于活动状态
	glGenBuffers( 1, &objmesh->objtrianglelist[ 0 ].vbo );
	
    
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 
				  objmesh->objtrianglelist[ 0 ].vbo );

    //以类似发送数组缓冲区的方式,将该索引数组发送到GPU
	glBufferData( GL_ELEMENT_ARRAY_BUFFER,
				  objmesh->objtrianglelist[ 0 ].n_indice_array *
				  sizeof( unsigned short ),
				  objmesh->objtrianglelist[ 0 ].indice_array,
				  GL_STATIC_DRAW );

	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 );


    //创建VAO
    //计算不同顶点数据之间的顶点数组跨度
	unsigned char attribute;
				  stride = sizeof( vec3 )+
						   sizeof( vec3 );

    //创建一个新的VAO索引,并使其保持活动状态
	glGenVertexArraysOES( 1, &objmesh->vao );

	glBindVertexArrayOES( objmesh->vao );

    
    //开始构建VAO列表绑定,其中包括相关的调用来设置数组缓冲区
	glBindBuffer( GL_ARRAY_BUFFER, objmesh->vbo );

    //在VAO列表中包括POSITION顶点属性调用
	attribute = PROGRAM_get_vertex_attrib_location( program, ( char * )"POSITION" );

	glEnableVertexAttribArray( attribute );

	glVertexAttribPointer( attribute,
						   3,
						   GL_FLOAT,
						   GL_FALSE,
						   stride,
						   ( void * )NULL );
    
    //--------------------------------------------------------
    
    //以处理顶点位置相同的方式处理顶点法线,但是顶点属性指针调用的最后一个参数稍有不同,必须指定距离下一个
    //数据类型的偏移量
	attribute = PROGRAM_get_vertex_attrib_location( program, ( char * )"NORMAL" );

	glEnableVertexAttribArray( attribute );

	glVertexAttribPointer( attribute,
						   3,
						   GL_FLOAT,
						   GL_FALSE,
						   stride,
						   BUFFER_OFFSET( sizeof( vec3 ) ) );
    
    //在关闭VAO列表之前绑定数组元素缓冲区(索引)
	glBindBuffer( GL_ELEMENT_ARRAY_BUFFER,
				  objmesh->objtrianglelist[ 0 ].vbo );					   

    //停用当前的VAO,其次对前面所调用的类似数组的所有命令进行编译,然后将它们与VAO索引相关亮
	glBindVertexArrayOES( 0 );
}
Exemple #18
0
void templateAppInit( int width, int height ) {

	atexit( templateAppExit );

	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_mesh( 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;

	texture = OBJ_get_texture( obj, ( char * )"projector", 0 );
	
	glBindTexture( GL_TEXTURE_2D, texture->tid );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );	
}