示例#1
0
_image *create_image (const char* file, int x, int y, int w, int h, float u_start, float v_start, float u_end, float v_end)
{
	_image *img=(_image *)calloc(1,sizeof(_image));
	
	img->x=x;
	img->y=y;
	img->w=w;
	img->h=h;
	img->u[0]=u_start;
	img->u[1]=u_end;
	img->v[0]=v_start;
	img->v[1]=v_end;

#ifdef	NEW_TEXTURES
	img->texture = load_texture_cached(file, tt_image);
#else	/* NEW_TEXTURES */
	img->texture=load_texture_cache(file,0);
#endif	/* NEW_TEXTURES */
	if(!img->texture) {
		free(img);
		img=NULL;
	}

	return img;
}
示例#2
0
void load_all_tiles()
{
	int i;
	int cur_text;
	char str[80];
	for(i=0;i<255;i++)
	{
		sprintf(str,"./3dobjects/tile%i.dds",i);
		if(is_water_tile(i) && is_reflecting(i)) cur_text=load_texture_cache(str,70);
		else cur_text=load_texture_cache(str,255);
		if(cur_text==-1)return;
		tile_list[i]=cur_text;
		tiles_no=i;
#ifdef	OLD_TEXTURE_LOADER
		//map_tiles[i].img=load_bmp8_color_key_no_texture_img(str,map_tiles+i,255);
		load_bmp8_texture(str,map_tiles+i,255);
#else	//OLD_TEXTURE_LOADER
		load_texture(str,map_tiles+i,255);
#endif	//OLD_TEXTURE_LOADER
	}
	map_tiles[255].texture=NULL;
}
示例#3
0
int load_font(int num, char *file)
{
	int	i;

	// error checking
	if(num < 0 || num >= 10)
		{
			return -1;
		}
	// allocate space if needed
	if(fonts[num] == NULL)
		{
			fonts[num]=(font_info *)calloc(1, sizeof(font_info));
			if(fonts[num] == NULL)
				{
					log_error("Unable to load font");
					return -1;
				}
		}
	//watch the highest font
	if(num >= max_fonts)
		{
			max_fonts=num+1;
		}
	// set default font info
	strcpy(fonts[num]->name, "default");
	fonts[num]->spacing=0;
	for(i=0; i<9*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12;
	// load texture
	fonts[num]->texture_id=load_texture_cache(file, 0);
	// load font information
	// TODO: write this and remove the hack!
	if(num > 0){
		static int widths[]={
			4,2,7,11,8,12,12,2,7,7,9,10,3,8,
			2,10,10,10,8,8,10,7,9,9,9,9,3,3,
			10,10,10,9,12,12,9,10,10,9,9,10,9,8,
			7,11,8,11,10,11,9,11,11,9,10,9,12,12,
			12,12,10,6,10,6,10,12,3,11,9,9,9,9,
			8,9,9,4,6,10,4,11,9,10,9,9,8,8,
			8,9,10,12,10,10,9,8,2,8,10,8,12,12,
			12,12,12,12,12,12,12,12,12,12,12,12,12,12,
			12,12,12,12,12,12,12,12,12,12,12,12,12,12,
		};
		memcpy(fonts[num]->widths, widths, sizeof(widths));
		fonts[num]->spacing=4;
	}

	//and return
	return num;
}
示例#4
0
int weather_parse_lightning(xmlNode *node)
{
	xmlAttr *attr;
	int ok = 1;
	int id = lightnings_defs_count++;

	lightnings_defs[id].texture = -1;
	lightnings_defs[id].coords[0] = 0.0;
	lightnings_defs[id].coords[1] = 0.0;
	lightnings_defs[id].coords[2] = 0.0;
	lightnings_defs[id].coords[3] = 0.0;

	for (attr = node->properties; attr; attr = attr->next)
	{
		if (attr->type == XML_ATTRIBUTE_NODE)
		{
			if (!xmlStrcasecmp (attr->name, (xmlChar*)"texture"))
#ifdef	NEW_TEXTURES
				lightnings_defs[id].texture = load_texture_cached((char*)attr->children->content, tt_mesh);
#else	/* NEW_TEXTURES */
				lightnings_defs[id].texture = load_texture_cache((char*)attr->children->content, 0);
#endif	/* NEW_TEXTURES */
			else if (!xmlStrcasecmp (attr->name, (xmlChar*)"x1"))
				lightnings_defs[id].coords[0] = atof((char*)attr->children->content);
			else if (!xmlStrcasecmp (attr->name, (xmlChar*)"y1"))
				lightnings_defs[id].coords[1] = atof((char*)attr->children->content);
			else if (!xmlStrcasecmp (attr->name, (xmlChar*)"x2"))
				lightnings_defs[id].coords[2] = atof((char*)attr->children->content);
			else if (!xmlStrcasecmp (attr->name, (xmlChar*)"y2"))
				lightnings_defs[id].coords[3] = atof((char*)attr->children->content);
			else {
				LOG_ERROR_OLD("unknown attribute for weather effect color: %s", (char*)attr->name);
				ok = 0;
			}
		}
	}
示例#5
0
void draw_game_map (int map, int mouse_mini)
{     
	int screen_x=0;
	int screen_y=0;
	int x=-1,y=-1;
	float x_size=0,y_size=0;
	GLuint map_small, map_large;
	actor *me;
	static int fallback_text = -1;

	// if we don't have a continent texture (instance may be), fallback to blank paper
	if (cont_text < 0)
	{
		if (fallback_text < 0)
#ifdef	NEW_TEXTURES
		{
			fallback_text = load_texture_cached("./textures/paper1", tt_gui);
		}
#else	/* NEW_TEXTURES */
			fallback_text = load_texture_cache ("./textures/paper1.bmp", 0);
#endif	/* NEW_TEXTURES */
		cont_text = fallback_text;
	}
	
	if(map){
#ifdef	NEW_TEXTURES
		map_small = cont_text;
#else	/* NEW_TEXTURES */
		map_small=get_texture_id(cont_text);
#endif	/* NEW_TEXTURES */
		if(inspect_map_text == 0) {
			map_large=map_text;
		} else {
			map_large = inspect_map_text;
		}
	} else {
		map_small=map_text;
#ifdef	NEW_TEXTURES
		map_large = cont_text;
#else	/* NEW_TEXTURES */
		map_large=get_texture_id(cont_text);
#endif	/* NEW_TEXTURES */
		if(cur_map!=-1){
			x_size = ((float)(continent_maps[cur_map].x_end - continent_maps[cur_map].x_start)) / tile_map_size_x;
			y_size = ((float)(continent_maps[cur_map].y_end - continent_maps[cur_map].y_start)) / tile_map_size_y;
		} else {
			x_size=y_size=0;
		}
	}
	
   	glDisable(GL_DEPTH_TEST);
   	glDisable(GL_LIGHTING);
    
	glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	
	glOrtho(300, (GLdouble)0, (GLdouble)0, 200, -250.0, 250.0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glDisable(GL_TEXTURE_2D);
	glColor3f(0.0f, 0.0f, 0.0f);

	glBegin(GL_QUADS);
		glVertex2i(0,   0);	
		glVertex2i(300, 0);
		glVertex2i(300, 200);
		glVertex2i(0,   200);
	glEnd();
	glEnable(GL_TEXTURE_2D);

	glColor3f(1.0f,1.0f,1.0f);
    	
#ifdef	NEW_TEXTURES
	bind_texture(map_large);

	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3i(50,0,0); 
		glTexCoord2f(1.0f, 0.0f); glVertex3i(50,200,0);
		glTexCoord2f(0.0f, 0.0f); glVertex3i(250,200,0);
		glTexCoord2f(0.0f, 1.0f); glVertex3i(250,0,0);
	glEnd();
#else	/* NEW_TEXTURES */
	bind_texture_id(map_large);

	glBegin(GL_QUADS);
		glTexCoord2f(1.0f,0.0f); glVertex3i(50,0,0); 
		glTexCoord2f(1.0f,1.0f); glVertex3i(50,200,0);
		glTexCoord2f(0.0f,1.0f); glVertex3i(250,200,0);
		glTexCoord2f(0.0f,0.0f); glVertex3i(250,0,0);
	glEnd();
#endif	/* NEW_TEXTURES */

	if (mouse_mini)
		glColor4f (1.0f, 1.0f, 1.0f, 1.0f);
	else
		glColor4f (0.7f, 0.7f, 0.7f, 0.7f);
    	
	glEnable(GL_ALPHA_TEST);
	
#ifdef	NEW_TEXTURES
	bind_texture(map_small);

    	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3i(250,150,0);
		glTexCoord2f(1.0f, 0.0f); glVertex3i(250,200,0);
		glTexCoord2f(0.0f, 0.0f); glVertex3i(300,200,0);
		glTexCoord2f(0.0f, 1.0f); glVertex3i(300,150,0);
	glEnd();
#else	/* NEW_TEXTURES */
	bind_texture_id(map_small);

    	glBegin(GL_QUADS);
		glTexCoord2f(1.0f,0.0f); glVertex3i(250,150,0);
		glTexCoord2f(1.0f,1.0f); glVertex3i(250,200,0);
		glTexCoord2f(0.0f,1.0f); glVertex3i(300,200,0);
		glTexCoord2f(0.0f,0.0f); glVertex3i(300,150,0);
	glEnd();
#endif	/* NEW_TEXTURES */
	
	glDisable(GL_ALPHA_TEST);
	
	glColor3f(1.0f,1.0f,1.0f);
    	
#ifdef	NEW_TEXTURES
	bind_texture(legend_text);

    	glBegin(GL_QUADS);
		glTexCoord2f(1.0f, 1.0f); glVertex3i(250,50,0);
		glTexCoord2f(1.0f, 0.0f); glVertex3i(250,150,0);
		glTexCoord2f(0.0f, 0.0f); glVertex3i(300,150,0);
		glTexCoord2f(0.0f, 1.0f); glVertex3i(300,50,0);
	glEnd();
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(legend_text);

    	glBegin(GL_QUADS);
		glTexCoord2f(1.0f,0.0f); glVertex3i(250,50,0);
		glTexCoord2f(1.0f,1.0f); glVertex3i(250,150,0);
		glTexCoord2f(0.0f,1.0f); glVertex3i(300,150,0);
		glTexCoord2f(0.0f,0.0f); glVertex3i(300,50,0);
	glEnd();
#endif	/* NEW_TEXTURES */

// this is necessary for the text over map
// need to execute this for any map now
// because of the coordinate display - Lachesis
	if(map/*&&(adding_mark||max_mark>0)*/){
   		glViewport(0, 0 + hud_y, window_width-hud_x, window_height-hud_y);
		glMatrixMode(GL_PROJECTION);
		glPushMatrix();
		glLoadIdentity();
		glOrtho((GLdouble)0, (GLdouble)300, (GLdouble)200, (GLdouble)0, -250.0, 250.0);
		glMatrixMode(GL_MODELVIEW);
		glPushMatrix();
		glLoadIdentity();

		// Draw help for toggling the mini-map
		{
			char buf[80];
			char keybuf[20];
			glEnable(GL_TEXTURE_2D);
			safe_snprintf(buf, sizeof(buf), "%s %s", win_minimap, get_key_string(K_MINIMAP, keybuf, sizeof(keybuf)));
			glColor3f (1.0f, 1.0f, 0.0f);
			draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 43, (const unsigned char *)buf, 1, 0.3);
		}
 
		// draw a temporary mark until the text is entered
		if (adding_mark) {
			int x = mark_x;
			int y = mark_y;

			screen_x=(51+200*x/(tile_map_size_x*6));
			screen_y=201-200*y/(tile_map_size_y*6);

			glColor3f(1.0f,1.0f,0.0f);
			glDisable(GL_TEXTURE_2D);
			glBegin(GL_LINES);
				glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
				glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);

				glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
				glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);
			glEnd();
		        glEnable(GL_TEXTURE_2D);
		        glColor3f(1.0f,1.0f,0.0f);
			draw_string_zoomed (screen_x, screen_y, (unsigned char*)input_text_line.data, 1, mapmark_zoom);
		}

		draw_mark_filter();
		if(inspect_map_text == 0) {
			draw_marks(marks, max_mark, tile_map_size_x, tile_map_size_y);
			draw_coordinates(tile_map_size_x, tile_map_size_y);
		}
		else {
			draw_marks(temp_marks, max_temp_mark, temp_tile_map_size_x, temp_tile_map_size_y);
			draw_coordinates(temp_tile_map_size_x, temp_tile_map_size_y);
		}
	}

	//if we're following a path, draw the destination on the map
	if (pf_follow_path && inspect_map_text == 0)
	{
		int px = pf_dst_tile->x;
		int py = pf_dst_tile->y;

		if (!map)
		{
			if (cur_map!=-1)
			{
				screen_x = 300 - (50 + 200 * ( (px * x_size / 6) + continent_maps[cur_map].x_start) / 512);
				screen_y = 200 * ( (py * y_size / 6) + continent_maps[cur_map].y_start) / 512;
			}
			else
			{
				screen_x = screen_y = 0;
			}
		} 
		else
		{
			screen_x=51 +200*px/(tile_map_size_x*6);
			screen_y=201-200*py/(tile_map_size_y*6);
		}

		glColor3f(1.0f,0.0f,0.0f);
		
		glDisable(GL_TEXTURE_2D);
		glBegin(GL_LINES);

		glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
		glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);

		glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
		glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);

		glEnd();
	}
	
	//ok, now let's draw our possition...
	if ( (me = get_our_actor ()) != NULL && inspect_map_text == 0)
	{
		x = me->x_tile_pos;
		y = me->y_tile_pos;
	}
	else
	{
		//We don't exist (usually happens when teleporting)
		x = -1;
		y = -1;
	}

	if (!map)
	{
		if (cur_map != -1)
		{
			screen_x = 300 - (50 + 200 * ( (x * x_size / 6) + continent_maps[cur_map].x_start) / 512);
			screen_y = 200 * ( (y * y_size / 6) + continent_maps[cur_map].y_start) / 512;
		}
		else
		{
			screen_x = screen_y = 0;
		}
	} 
	else 
	{
		screen_x=51 +200*x/(tile_map_size_x*6);
		screen_y=201-200*y/(tile_map_size_y*6);
	}
	
	if ( (map || !dungeon) && x != -1 )
	{
		glColor3f (0.0f, 0.0f, 1.0f);
		glDisable (GL_TEXTURE_2D);
		glBegin (GL_LINES);

		glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
		glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);

		glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
		glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);

		glEnd();
	}

	if(!map && show_continent_map_boundaries && cont_text!=fallback_text) {
		int i;
		/* Convert mouse coordinates to map coordinates (stolen from pf_get_mouse_position()) */
		int min_mouse_x = (window_width-hud_x)/6;
		int min_mouse_y = 0;
		int max_mouse_x = min_mouse_x+((window_width-hud_x)/1.5);
		int max_mouse_y = window_height - hud_y;
		int screen_map_width = max_mouse_x - min_mouse_x;
		int screen_map_height = max_mouse_y - min_mouse_y;
		int m_px = ((mouse_x-min_mouse_x) * 512) / screen_map_width;
		int m_py = 512 - ((mouse_y * 512) / screen_map_height);
		int mouse_over = -1;

		glColor3f (0.267f, 0.267f, 0.267f);
		glDisable (GL_TEXTURE_2D);
		glBegin(GL_LINES);
		/* Draw borders for the maps except the one with the mouse over it */
		glColor3f (0.267f, 0.267f, 0.267f);
		for(i = 0; continent_maps[i].name != NULL; i++) {
			if(continent_maps[i].cont == continent_maps[cur_map].cont) {
				if(!mouse_mini && mouse_over == -1
				&& m_px > continent_maps[i].x_start && m_px < continent_maps[i].x_end
				&& m_py > continent_maps[i].y_start && m_py < continent_maps[i].y_end)
				{
					/* Mouse over this map */
					mouse_over = i;
				} else {
					int x_start = 300-(50+200*continent_maps[i].x_start/512);
					int x_end = 300-(50+200*continent_maps[i].x_end/512);
					int y_start = 200*continent_maps[i].y_start / 512;
					int y_end = 200*continent_maps[i].y_end / 512;
					
					glVertex2i(x_start, y_start);
					glVertex2i(x_start, y_end);

					glVertex2i(x_start, y_end);
					glVertex2i(x_end, y_end);

					glVertex2i(x_end, y_end);
					glVertex2i(x_end, y_start);

					glVertex2i(x_end, y_start);
					glVertex2i(x_start, y_start);
				}
			}
		}
		/* Draw border for the map with the mouse over it */
		if(mouse_over >= 0) {
			float flash_effect_colour = 0.90f - sin((float)SDL_GetTicks()/100.0f) / 10.0f;
			int x_start = 300-(50+200*continent_maps[mouse_over].x_start/512);
			int x_end = 300-(50+200*continent_maps[mouse_over].x_end/512);
			int y_start = 200*continent_maps[mouse_over].y_start / 512;
			int y_end = 200*continent_maps[mouse_over].y_end / 512;

			glColor3f(flash_effect_colour, flash_effect_colour, flash_effect_colour);
			glVertex2i(x_start, y_start);
			glVertex2i(x_start, y_end);

			glVertex2i(x_start, y_end);
			glVertex2i(x_end, y_end);

			glVertex2i(x_end, y_end);
			glVertex2i(x_end, y_start);

			glVertex2i(x_end, y_start);
			glVertex2i(x_start, y_start);
		}
		glEnd();
	}

#ifdef DEBUG_MAP_SOUND
	// If we are in map view (not continent view) draw the sound area boundaries
	if (map) {
		print_sound_boundaries(cur_tab_map);
	}
#endif // DEBUG_MAP_SOUND

	if (map)
	{
		glMatrixMode(GL_MODELVIEW);
		glPopMatrix();
		glMatrixMode(GL_PROJECTION);
		glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
	}

	glEnable (GL_TEXTURE_2D);
	glColor3f (1.0f, 1.0f, 1.0f);

	glMatrixMode (GL_MODELVIEW);
	glPopMatrix ();
	glMatrixMode (GL_PROJECTION);
	glPopMatrix ();
	glMatrixMode (GL_MODELVIEW);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
#ifdef OPENGL_TRACE
	CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
示例#6
0
int switch_to_game_map()
{
#ifdef	NEW_TEXTURES
	char buffer[1024];
#else	/* NEW_TEXTURES */
	int len;
	texture_cache_struct tex;
#endif	/* NEW_TEXTURES */
	short int cur_cont;
	static short int old_cont = -1;
	
	/* check we loaded the mapinfo data */
	if (continent_maps == NULL || continent_maps[0].name == NULL)
	{
		LOG_TO_CONSOLE(c_yellow2,err_nomap_str);
		return 0;
	}
	
#ifdef	NEW_TEXTURES
	if (check_image_name(map_file_name, sizeof(buffer), buffer) == 1)
	{
		map_text = load_texture_cached(buffer, tt_image);
	}
	else
	{
		map_text = 0;
	}
#else	/* NEW_TEXTURES */
	my_strcp(tex.file_name,map_file_name);
	len=strlen(tex.file_name);
	tex.file_name[len-3]='b';
	tex.file_name[len-2]='m';
	tex.file_name[len-1]='p';
	tex.alpha = 128;
	if (!el_file_exists(tex.file_name))
		map_text = 0;
	else
		map_text=load_bmp8_fixed_alpha(&tex, tex.alpha);
#endif	/* NEW_TEXTURES */
	if(!map_text)
	{
		LOG_TO_CONSOLE(c_yellow2,err_nomap_str);
		return 0;
	}
	
	if (cur_map < 0)
	{
		cur_cont = -1;
	}
	else
	{
		cur_cont = continent_maps[cur_map].cont;
	}
	if (cur_cont != old_cont && cur_cont >= 0 && cur_cont < nr_continents)
	{
#ifdef	NEW_TEXTURES
		cont_text = load_texture_cached (cont_map_file_names[cur_cont], tt_image);
#else	/* NEW_TEXTURES */
		cont_text = load_texture_cache (cont_map_file_names[cur_cont], 128);
#endif	/* NEW_TEXTURES */
		old_cont = cur_cont;
	}
#ifdef DEBUG_MAP_SOUND
	cur_tab_map = cur_map;
#endif // DEBUG_MAP_SOUND
	
	if(current_cursor != CURSOR_ARROW)
	{
		change_cursor(CURSOR_ARROW);
	}
	return 1;
}
示例#7
0
void init_stuff()
{
	int i;
	int seed;

	chdir(DATA_DIR);
	
#ifndef WINDOWS
	setlocale(LC_NUMERIC,"en_US");
#endif
	init_translatables();

	//create_error_mutex();
	init_globals();
	init_crc_tables();
	init_zip_archives();
	cache_system_init(MAX_CACHE_SYSTEM);
	init_texture_cache();

	init_vars();
	
	read_config();

	file_check_datadir();

#ifdef LOAD_XML
	//Well, the current version of the map editor doesn't support having a datadir - will add that later ;-)
	load_translatables();
#endif

#ifdef LINUX
#ifdef GTK2
	init_filters();
#else
	file_selector = create_fileselection();
#endif
#endif	//LINUX

	init_gl();

	window_resize();
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LESS);
//	glDepthFunc(GL_LEQUAL);
    glEnable(GL_TEXTURE_2D);
	glShadeModel(GL_SMOOTH);
	glFrontFace(GL_CCW);
	glCullFace(GL_BACK);
	glEnable(GL_NORMALIZE);
	glClearColor( 0.0, 0.0, 0.0, 0.0 );
	glClearStencil(0);

	seed = time (NULL);
  	srand (seed);

	init_texture_cache();
	init_particles ();
	init_e3d_cache();
	init_2d_obj_cache();

	for(i=0; i<256; i++)
        tile_list[i]=0;

	for (i = 0; i < MAX_LIGHTS; i++)
		lights_list[i] = NULL;

	new_map(256,256);
	load_all_tiles();

	//lights setup
	build_global_light_table();
	build_sun_pos_table();
	reset_material();
	init_lights();
	//disable_local_lights();
	//clear_error_log();

	// Setup the new eye candy system
#ifdef	EYE_CANDY
	ec_init();
#endif	//EYE_CANDY

	init_gl_extensions();

	if(have_multitexture)
#ifdef	NEW_TEXTURES
		ground_detail_text = load_texture_cached("./textures/ground_detail.bmp", tt_mesh);
#else	/* NEW_TEXTURES */
		ground_detail_text = load_texture_cache ("./textures/ground_detail.bmp",255);
#endif	/* NEW_TEXTURES */

	//load the fonts texture
	init_fonts();
#ifdef	NEW_TEXTURES
	icons_text=load_texture_cached("./textures/gamebuttons.bmp", tt_gui);
	buttons_text=load_texture_cached("./textures/buttons.bmp", tt_gui);
#else	/* NEW_TEXTURES */
	icons_text=load_texture_cache("./textures/gamebuttons.bmp",0);
	buttons_text=load_texture_cache("./textures/buttons.bmp",0);
#endif	/* NEW_TEXTURES */
	//get the application home dir

	have_multitexture=0;//debug only

#ifndef LINUX
	GetCurrentDirectory(sizeof(exec_path),exec_path);
#else
	exec_path[0]='.';exec_path[1]='/';exec_path[2]=0;
#endif
	init_browser();

    if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
    { 
        char str[120];
        snprintf(str, sizeof(str), "Couldn't initialize the timer: %s\n", SDL_GetError());
        log_error(__FILE__, __LINE__, str);
        SDL_Quit();
	    exit(1);
    }

	SDL_SetTimer (1000/(18*4), my_timer);

	SDL_EnableUNICODE(1);

    //we might want to do this later.

	// creating windows
	display_browser();
	toggle_window(browser_win);

	display_o3dow();
	toggle_window(o3dow_win);

	display_replace_window();
	toggle_window(replace_window_win);

	display_edit_window();
	toggle_window(edit_window_win);

	create_particles_window ();
}
示例#8
0
int load_font_textures ()
{
#ifndef	NEW_TEXTURES
	int poor_man_save=poor_man;
	int use_mipmaps_save=use_mipmaps;
#endif	/* NEW_TEXTURES */
	size_t i = 0;
	char *glob_pattern;
#ifdef WINDOWS
	struct _finddata_t c_file;
	long hFile;
#else //WINDOWS
	int ret;
	glob_t glob_res;
	size_t j;
#endif //WINDOWS
	char file[60] = "";
	char str[60] = "";

	if (fonts[0] == NULL || fonts[1] == NULL || fonts[2] == NULL || fonts[3]==NULL )
	{
		for (i = 0; i < FONTS_ARRAY_SIZE; i++) {
			if (fonts[i] != NULL)
				free (fonts[i]);
			fonts[i] = NULL;
		}
		if ( !init_fonts () ) return 0;
	}

#ifndef	NEW_TEXTURES
	poor_man=0;
	use_mipmaps=0;
#endif	/* NEW_TEXTURES */

#ifdef	NEW_TEXTURES
	fonts[0]->texture_id = load_texture_cached("textures/font.dds", tt_font);
#else	/* NEW_TEXTURES */
	fonts[0]->texture_id = load_texture_cache("./textures/font.bmp", 0);
#endif	/* NEW_TEXTURES */
	i = 1;
	// Force the selection of the base font.
	add_multi_option("chat_font", "Type 1");
	add_multi_option("name_font", "Type 1");
	// Find what font's exist and load them
	glob_pattern = malloc(strlen(datadir)+sizeof(texture_dir)+10+1); //+10 = font*.bmp*
#ifdef	NEW_TEXTURES
	sprintf(glob_pattern, "%s%sfont*.dds", datadir, texture_dir);
#else	/* NEW_TEXTURES */
	sprintf(glob_pattern, "%s%sfont*.bmp*", datadir, texture_dir);
#endif	/* NEW_TEXTURES */
#ifdef WINDOWS
	if( (hFile = _findfirst( glob_pattern, &c_file )) == -1L ){
		free(glob_pattern);
		return 0;
	}
	do {
		int	len;

		safe_strncpy(file, c_file.name, sizeof(file));
#else //!WINDOWS
	ret = glob(glob_pattern, 0, NULL, &glob_res);
	if(ret != 0) {
		LOG_ERROR("Unable to find any font textures\n");
		free(glob_pattern);
		return 0;
	}
	j = 0;
	while (j < glob_res.gl_pathc && i < FONTS_ARRAY_SIZE) {
		int	len;

		safe_strncpy(file, glob_res.gl_pathv[j]+sizeof(texture_dir)-1+strlen(datadir), sizeof(file));
#endif //WINDOWS
		len= strlen(file);
#ifdef	NEW_TEXTURES
		if (((len + sizeof(texture_dir) - 1) < sizeof(str)) && !strncasecmp(file, "font", 4)
			&& has_suffix(file, len, ".dds", 4))
		{
			safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers.
			file[len - 4] = 0;
			fonts[i]->texture_id = load_texture_cached(str, tt_font);
#else	/* NEW_TEXTURES */
		if (len+sizeof(texture_dir)-1 < sizeof(str) && !strncasecmp(file, "font", 4)
				&& (has_suffix(file, len, ".bmp", 4) || has_suffix(file, len, ".bmp.gz", 7))
				&& (!has_suffix(file, len, "_alpha.bmp", 10)) && (!has_suffix(file, len, "_alpha.bmp.gz", 13))) {
			// Get the filename, remove the .bmp and add _alpha.bmp to a copy, then replace the .bmp
			safe_snprintf(str, sizeof(str), "./textures/%s", file); //Use a relative path here, load_texture_cache_deferred() is using the path wrappers.
			if(has_suffix(file, len, ".bmp.gz", 7)){
				file[len - 7]= 0;
			} else {
				file[len - 4]= 0;
			}
			fonts[i]->texture_id = load_texture_cache_deferred(str, 0);
#endif	/* NEW_TEXTURES */
			safe_snprintf(font_names[i], sizeof(font_names[i]), "Type %i - %s", i + 1, file);
			add_multi_option("chat_font", font_names[i]);
			add_multi_option("name_font", font_names[i]);
			i++;
		}
#ifndef WINDOWS
		j++;
#endif //WINDOWS
	}
#ifdef WINDOWS
	while ( _findnext( hFile, &c_file ) == 0 );
	_findclose( hFile );
#else //!WINDOWS
	globfree(&glob_res);
#endif //WINDOWS
	free(glob_pattern);

#ifndef	NEW_TEXTURES
	poor_man=poor_man_save;
	use_mipmaps=use_mipmaps_save;
#endif	/* NEW_TEXTURES */

	//set the default font
	cur_font_num = 0;
	font_text = fonts[0]->texture_id;

	return 1;
}

int set_font_parameters (int num)
{
	int	i;

	// error checking
	if(num < 0 || num >= FONTS_ARRAY_SIZE)
		{
			return -1;
		}
	// allocate space if needed
	if(fonts[num] == NULL)
		{
			fonts[num]=(font_info *)calloc(1, sizeof(font_info));
			if(fonts[num] == NULL)
				{
					LOG_ERROR(cant_load_font);
					return -1;
				}
		}
	//watch the highest font
	if(num >= max_fonts)
		{
			max_fonts=num+1;
		}
	// set default font info
	my_strcp (fonts[num]->name, "default");
	fonts[num]->spacing=0;

	// load font information
	// TODO: write this and remove the hack!
	if(num!=1||num!=2)for(i=0; i<FONTS_ARRAY_SIZE*FONT_CHARS_PER_LINE; i++) fonts[num]->widths[i]=12;
	if(num==1){
		static int widths[]={
			4,2,7,11,8,12,12,2,7,7,9,10,3,8,
			2,10,10,10,8,8,10,7,9,9,9,9,3,3,
			10,10,10,9,12,12,9,10,10,9,9,10,9,8,
			7,11,8,11,10,11,9,11,11,9,10,9,12,12,
			12,12,10,6,10,6,10,12,3,11,9,9,9,9,
			8,9,9,4,6,10,4,11,9,10,9,9,8,8,
			8,9,10,12,10,10,9,8,2,8,10,8,12,12,
			12,12,12,12,12,12,12,12,12,12,12,12,12,12,
			12,12,12,12,12,12,12,12,12,12,12,12,12,12,
			12,12,12,12,12,12,12,12,12,12,12,12,12,12,
		};
		memcpy(fonts[num]->widths, widths, sizeof(widths));
		fonts[num]->spacing=4;
	}
	if(num==2){
		static int widths[]={
			 8,  8,  8, 10,  8, 10, 10,  8,  8,  8,  8, 10,  8,  8,
			 8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
			10, 10, 10,  8, 12, 10, 10, 10, 10, 10, 10, 10, 10, 10,
			10, 10, 10, 10, 10, 10, 10, 10,  8, 10, 10, 10, 10, 10,
			10, 10, 10, 10, 10, 10, 10,  8,  8,  8,  8,  8,  8,  8,
			10,  8,  8,  8,  8,  8,  8, 10,  8,  8,  8,  8,  8,  8,
			 8,  8,  8, 10,  8,  8,  8, 10,  8, 10, 10,  8, 10,  8,
			 8,  8, 10, 10, 10,  8, 10, 10,  8,  8,  8, 12, 12, 12,
			10, 10, 12, 10, 12, 12, 12,
		};
		memcpy(fonts[num]->widths, widths, sizeof(widths));
		fonts[num]->spacing=2;
	}

	//and return
	return num;
}


int	set_font(int num)
{
	if(num >= 0 && num < max_fonts && fonts[num] && fonts[num]->texture_id >= 0)
		{
			cur_font_num=num;
			font_text=fonts[cur_font_num]->texture_id;
		}

	return cur_font_num;
}
示例#9
0
void init_stuff()
{
	int seed;

	Uint32 (*my_timer_pointer) (unsigned int) = my_timer;

	//TODO: process command line options
	chdir(datadir);

	//Initialize all strings
	init_translatables();

#ifdef WRITE_XML
	load_translatables();//Write to the current working directory - hopefully we'll have write rights here...
#endif

	//read the config file
	read_config();

	//Parse command line options
	read_command_line();

	//OK, we have the video mode settings...
	setup_video_mode(full_screen,video_mode);
	//now you may set the video mode using the %<foo> in-game
	video_mode_set=1;

	//Good, we should be in the right working directory - load all translatables from their files
	load_translatables();

	init_video();
	resize_window();
	init_gl_extensions();
#ifdef CAL3D
	create_cal3d_model();
	init_cal3d_model();
#endif
	seed = time (NULL);
	srand (seed);

	cache_system_init(MAX_CACHE_SYSTEM);
	init_texture_cache();
	init_md2_cache();
	init_e3d_cache();
	init_2d_obj_cache();
	load_ignores();
	load_filters();
	load_e3d_list();
	load_e2d_list();
	load_part_list();
	load_knowledge_list();
	load_cursors();
	build_cursors();
	change_cursor(CURSOR_ARROW);
	build_glow_color_table();


	init_actors_lists();
	memset(tile_list, 0, sizeof(tile_list));
	memset(lights_list, 0, sizeof(lights_list));
	init_particles_list();
	memset(actors_defs, 0, sizeof(actors_defs));
	init_actor_defs();

	load_map_tiles();

	//lights setup
	build_global_light_table();
	build_sun_pos_table();
	reset_material();
	init_lights();
	disable_local_lights();
	init_colors();
	clear_error_log();
	clear_conn_log();
	clear_thunders();
	build_rain_table();
	read_bin_cfg();
	build_levels_table();//for some HUD stuff
	init_scale_array();

	if(!no_sound)init_sound();

	//initialize the fonts
	init_fonts();
	check_gl_errors();

	//load the necesary textures
	//font_text=load_texture_cache("./textures/font.bmp",0);
	icons_text=load_texture_cache("./textures/gamebuttons.bmp",0);
	hud_text=load_texture_cache("./textures/gamebuttons2.bmp",0);
	cons_text=load_texture_cache("./textures/console.bmp",255);
	sky_text_1=load_texture_cache("./textures/sky.bmp",70);
	particle_textures[0]=load_texture_cache("./textures/particle0.bmp",0);
	particle_textures[1]=load_texture_cache("./textures/particle1.bmp",0);
	particle_textures[2]=load_texture_cache("./textures/particle2.bmp",0);
	particle_textures[3]=load_texture_cache("./textures/particle3.bmp",0);
	particle_textures[4]=load_texture_cache("./textures/particle4.bmp",0);
	particle_textures[5]=load_texture_cache("./textures/particle5.bmp",0);
	particle_textures[6]=load_texture_cache("./textures/particle6.bmp",0);
	particle_textures[7]=load_texture_cache("./textures/particle7.bmp",0);

	items_text_1=load_texture_cache("./textures/items1.bmp",0);
	items_text_2=load_texture_cache("./textures/items2.bmp",0);
	items_text_3=load_texture_cache("./textures/items3.bmp",0);
	items_text_4=load_texture_cache("./textures/items4.bmp",0);
	items_text_5=load_texture_cache("./textures/items5.bmp",0);
	items_text_6=load_texture_cache("./textures/items6.bmp",0);
	items_text_7=load_texture_cache("./textures/items7.bmp",0);
	items_text_8=load_texture_cache("./textures/items8.bmp",0);
	items_text_9=load_texture_cache("./textures/items9.bmp",0);

	portraits1_tex=load_texture_cache("./textures/portraits1.bmp",0);
	portraits2_tex=load_texture_cache("./textures/portraits2.bmp",0);
	portraits3_tex=load_texture_cache("./textures/portraits3.bmp",0);
	portraits4_tex=load_texture_cache("./textures/portraits4.bmp",0);
	portraits5_tex=load_texture_cache("./textures/portraits5.bmp",0);
	halo_tex=load_texture_cache("./textures/halo.bmp",0);

	if(have_multitexture)ground_detail_text=load_texture_cache("./textures/ground_detail.bmp",255);
	check_gl_errors();
	create_char_error_str[0]=0;
	init_opening_interface();
	init_hud_interface();

	if(SDLNet_Init()<0)
 		{
			char str[120];
			sprintf(str,"%s: %s\n",failed_sdl_net_init,SDLNet_GetError());
			log_error(str);
			SDLNet_Quit();
			SDL_Quit();
			exit(2);
		}

	if(SDL_InitSubSystem(SDL_INIT_TIMER)<0)
		{
 			char str[120];
			sprintf(str, "%s: %s\n", failed_sdl_timer_init,SDL_GetError());
			log_error(str);
			SDL_Quit();
		 	exit(1);
		}
	SDL_SetTimer (1000/(18*4), my_timer_pointer);

	ReadXML("languages/en/Encyclopedia/index.xml");
	read_key_config();
	load_questlog();
	init_buddy();

	//initiate function pointers
	init_attribf();

	//we might want to do this later.
	connect_to_server();
}
示例#10
0
int weather_parse_effect(xmlNode *node)
{
	xmlNode *item;
	xmlAttr *attr;
	int ok = 1;
	int id = -1;

	for (attr = node->properties; attr; attr = attr->next)
	{
		if (attr->type == XML_ATTRIBUTE_NODE)
		{
			if (!xmlStrcasecmp (attr->name, (xmlChar*)"id"))
				id = atoi((char*)attr->children->content);
			else {
				LOG_ERROR_OLD("unknown attribute for effect: %s", (char*)attr->name);
				ok = 0;
			}
		}
	}

	if (id < 1)
	{
		LOG_ERROR_OLD("wrong or missing id for weather effect");
		return 0;
	}

	for(item = node->children; item; item = item->next) {
		if(item->type == XML_ELEMENT_NODE) {
			if (xmlStrcasecmp(item->name, (xmlChar*)"sprites") == 0) {
				weather_defs[id].use_sprites = get_bool_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"density") == 0) {
				weather_defs[id].density = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"color") == 0) {
				weather_defs[id].color[0] = 0.0;
				weather_defs[id].color[1] = 0.0;
				weather_defs[id].color[2] = 0.0;
				weather_defs[id].color[3] = 0.0;
				for (attr = item->properties; attr; attr = attr->next)
				{
					if (attr->type == XML_ATTRIBUTE_NODE)
					{
						if (!xmlStrcasecmp (attr->name, (xmlChar*)"r"))
							weather_defs[id].color[0] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"g"))
							weather_defs[id].color[1] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"b"))
							weather_defs[id].color[2] = atof((char*)attr->children->content);
						else if (!xmlStrcasecmp (attr->name, (xmlChar*)"a"))
							weather_defs[id].color[3] = atof((char*)attr->children->content);
						else {
							LOG_ERROR_OLD("unknown attribute for weather effect color: %s", (char*)attr->name);
							ok = 0;
						}
					}
				}
				weather_defs[id].color[0] /= 255.0;
				weather_defs[id].color[1] /= 255.0;
				weather_defs[id].color[2] /= 255.0;
				weather_defs[id].color[3] /= 255.0;
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"size") == 0) {
				weather_defs[id].size = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"speed") == 0) {
				weather_defs[id].speed = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"wind_effect") == 0) {
				weather_defs[id].wind_effect = get_float_value(item);
			}
			else if (xmlStrcasecmp(item->name, (xmlChar*)"texture") == 0) {
#ifdef	NEW_TEXTURES
				weather_defs[id].texture = load_texture_cached((char*)item->children->content, tt_mesh);
#else	/* NEW_TEXTURES */
				weather_defs[id].texture = load_texture_cache((char*)item->children->content, 0);
#endif	/* NEW_TEXTURES */
			}
			else {
				LOG_ERROR_OLD("unknown node for weather effect: %s", item->name);
				ok = 0;
			}
		}
		else if (item->type == XML_ENTITY_REF_NODE) {
			ok &= weather_parse_effect(item->children);
		}
	}

	return ok;
}
示例#11
0
static e3d_object* do_load_e3d_detail(e3d_object* cur_object)
{
	e3d_header header;
	e3d_material material;
	char cur_dir[1024];
	int i, idx, l, mem_size, vertex_size, material_size;
	int file_pos, indices_size, index_size;
	char text_file_name[1024];
	Uint32 tmp;
	Uint16 tmp_16;
	Uint8* index_pointer;
	el_file_ptr file;
	version_number version;
	
	if (cur_object == 0) return 0;

	memset(cur_dir, 0, sizeof(cur_dir));
	//get the current directory
	l = strlen(cur_object->file_name);
	//parse the string backwards, until we find a /
	while (l > 0)
	{
		if ((cur_object->file_name[l] == '/') || (cur_object->file_name[l] == '\\')) break;
		l--;
	}

	i = 0;
	if (l)//prevent invalid dir names
	{
		while (l >= 0)
		{
			cur_dir[i] = cur_object->file_name[i];
			i++;
			l--;
		}
		cur_dir[i+1] = 0;
	}

	LOG_DEBUG_OLD("Loading e3d file '%s'.", cur_object->file_name);

	file = el_open(cur_object->file_name);
	if (file == 0)
	{
		LOG_ERROR_OLD("Can't open file '%s'!", cur_object->file_name);

		free_e3d_pointer(cur_object);

		return 0;
	}

	if (read_and_check_elc_header(file, EL3D_FILE_MAGIC_NUMBER, &version, cur_object->file_name) != 0)
	{
		LOG_ERROR_OLD("File '%s' has wrong header!", cur_object->file_name);

		free_e3d_pointer(cur_object);
		el_close(file);

		return 0;
	}
	
	el_read(file, sizeof(e3d_header), &header);

	cur_object->vertex_no = SDL_SwapLE32(header.vertex_no);
	cur_object->index_no = SDL_SwapLE32(header.index_no);
	cur_object->material_no = SDL_SwapLE32(header.material_no);
	vertex_size = SDL_SwapLE32(header.vertex_size);
	material_size = SDL_SwapLE32(header.material_size);
	index_size = SDL_SwapLE32(header.index_size);

	LOG_DEBUG_OLD("E3d file vertex count %d and size %d.",
		cur_object->vertex_no, vertex_size);

	LOG_DEBUG_OLD("E3d file index count %d and size %d.",
		cur_object->index_no, index_size);

	LOG_DEBUG_OLD("E3d file material count %d and size %d.",
		cur_object->material_no, material_size);

	LOG_DEBUG_OLD("E3d file version %d.%d.%d.%d.", version[0],
		version[1], version[2], version[3]);

	if ((version[0] == 1) && (version[1] == 1))
	{
		if ((header.vertex_options & 0xF0) != 0)
		{
			LOG_ERROR_OLD("Unknow options (%d) for file %s.",
				header.vertex_options, cur_object->file_name);
		}

		header.vertex_options &= 0x0F;

		if ((header.vertex_format & 0xE0) != 0)
		{
			LOG_ERROR_OLD("Unknow format (%d) for file %s.",
				header.vertex_format, cur_object->file_name);
		}

		header.vertex_format &= 0x1F;
	}
	else
	{
		if ((version[0] == 1) && (version[1] == 0))
		{
			header.vertex_format = 0;
			header.vertex_options ^= 0x01;
			header.vertex_options &= 0x07;
		}
		else
		{
			LOG_ERROR_OLD("File '%s' has wrong version number!",
				cur_object->file_name);

			free_e3d_pointer(cur_object);
			el_close(file);

			return 0;
		}
	}

	idx = 0;

	if (has_normal(header.vertex_options))
	{
		idx += 1;
	}

	if (has_color(header.vertex_options))
	{
		idx += 2;
	}

	cur_object->vertex_layout = &(vertex_layout_array[idx]);

	// They have at least the size we expected

	if (check_vertex_size(vertex_size, header.vertex_options, header.vertex_format) == 0)
	{
		LOG_ERROR_OLD("File '%s' has wrong vertex size!", cur_object->file_name);

		free_e3d_pointer(cur_object);
		el_close(file);

		return 0;
	}

	if (material_size != get_material_size(header.vertex_options))
	{
		LOG_ERROR_OLD("File '%s' has wrong material size! Expected size %d, found size %d.",
			cur_object->file_name, get_material_size(header.vertex_options), material_size);
		free_e3d_pointer(cur_object);
		el_close(file);
		return 0;
	}

	if (short_index(header.vertex_format))
	{
		if (index_size != sizeof(Uint16))
		{
			LOG_ERROR_OLD("File '%s' has wrong index size! Expected size %d, found size %d.",
				cur_object->file_name, sizeof(Uint16), index_size);
			free_e3d_pointer(cur_object);
			el_close(file);
			return 0;
		}
	}
	else
	{
		if (index_size != sizeof(Uint32))
		{
			LOG_ERROR_OLD("File '%s' has wrong index size! Expected size %d, found size %d.",
				cur_object->file_name, sizeof(Uint32), index_size);
			free_e3d_pointer(cur_object);
			el_close(file);
			return 0;
		}
	}

	LOG_DEBUG_OLD("Reading vertices at %d from e3d file '%s'.",
		SDL_SwapLE32(header.vertex_offset), cur_object->file_name);
	// Now reading the vertices
	el_seek(file, SDL_SwapLE32(header.vertex_offset), SEEK_SET);

	cur_object->vertex_data = malloc(cur_object->vertex_no * cur_object->vertex_layout->size);
	mem_size = cur_object->vertex_no * cur_object->vertex_layout->size;
	if (!CHECK_POINTER(cur_object->vertex_data, "vertex data")) return 0;

	read_vertex_buffer(file, (float*)(cur_object->vertex_data), cur_object->vertex_no,
		vertex_size, header.vertex_options, header.vertex_format);

	LOG_DEBUG_OLD("Reading indices at %d from e3d file '%s'.",
		SDL_SwapLE32(header.index_offset), cur_object->file_name);
	// Now reading the indices
	el_seek(file, SDL_SwapLE32(header.index_offset), SEEK_SET);

	if (cur_object->index_no < 65536)
	{
		indices_size = 2;
		cur_object->index_type = GL_UNSIGNED_SHORT;
	}
	else
	{
		indices_size = 4;
		cur_object->index_type = GL_UNSIGNED_INT;
	}

	cur_object->indices = malloc(cur_object->index_no * indices_size);

	index_pointer = 0;

	for (i = 0; i < cur_object->index_no; i++)
	{
		if (index_size == 2)
		{
			el_read(file, sizeof(Uint16), &tmp_16);
			tmp = SDL_SwapLE16(tmp_16);
		}
		else
		{
			el_read(file, sizeof(Uint32), &tmp);
			tmp = SDL_SwapLE32(tmp);
		}

		if (indices_size == 2)
		{
			((Uint16*)(cur_object->indices))[i] = tmp;
		}
		else
		{
			((Uint32*)(cur_object->indices))[i] = tmp;
		}
	}

	// only allocate the materials structure if it doesn't exist (on initial load)
	if (cur_object->materials == 0)
	{
		cur_object->materials = (e3d_draw_list*)malloc(cur_object->material_no*sizeof(e3d_draw_list));
		if (!CHECK_POINTER(cur_object->materials, "materials")) return 0;
		memset(cur_object->materials, 0, cur_object->material_no * sizeof(e3d_draw_list));
	}
	mem_size += cur_object->material_no * sizeof(e3d_draw_list);

	LOG_DEBUG_OLD("Reading materials at %d from e3d file '%s'.",
		SDL_SwapLE32(header.material_offset), cur_object->file_name);
	// Now reading the materials
	el_seek(file, SDL_SwapLE32(header.material_offset), SEEK_SET);
	
	cur_object->min_x = 1e10f;
	cur_object->min_y = 1e10f;
	cur_object->min_z = 1e10f;
	cur_object->max_x = -1e10f;
	cur_object->max_y = -1e10f;
	cur_object->max_z = -1e10f;
	cur_object->max_size = -1e10f;

	for (i = 0; i < cur_object->material_no; i++)
	{
		
		file_pos = el_tell(file);
		el_read(file, sizeof(e3d_material), &material);
		safe_snprintf(text_file_name, sizeof(text_file_name), "%s%s", cur_dir, material.material_name);

		cur_object->materials[i].options = SDL_SwapLE32(material.options);
#ifdef	MAP_EDITOR
#ifdef	NEW_TEXTURES
		cur_object->materials[i].texture = load_texture_cached(text_file_name, tt_mesh);
#else	/* NEW_TEXTURES */
		cur_object->materials[i].texture = load_texture_cache(text_file_name,0);
#endif	/* NEW_TEXTURES */
#else	//MAP_EDITOR
#ifdef	NEW_TEXTURES
		cur_object->materials[i].texture = load_texture_cached(text_file_name, tt_mesh);
#else	/* NEW_TEXTURES */
#ifdef	NEW_ALPHA
		// prepare to load the textures depending on if it is transparent or not (diff alpha handling)
		if (material_is_transparent(cur_object->materials[i].options))
		{	// is this object transparent?
			cur_object->materials[i].texture= load_texture_cache_deferred(text_file_name, -1);
		}
		else
		{
			cur_object->materials[i].texture= load_texture_cache_deferred(text_file_name, -1);	//255);
		}
#else	//NEW_ALPHA
//		cur_object->materials[i].texture = load_texture_cache_deferred(text_file_name, 255);
		cur_object->materials[i].texture = load_texture_cache_deferred(text_file_name, 0);
#endif	//NEW_ALPHA
#endif	/* NEW_TEXTURES */
#endif	//MAP_EDITOR

		cur_object->materials[i].min_x = SwapLEFloat(material.min_x);
		cur_object->materials[i].min_y = SwapLEFloat(material.min_y);
		cur_object->materials[i].min_z = SwapLEFloat(material.min_z);
		cur_object->materials[i].max_x = SwapLEFloat(material.max_x);
		cur_object->materials[i].max_y = SwapLEFloat(material.max_y);
		cur_object->materials[i].max_z = SwapLEFloat(material.max_z);
		// calculate the max size for cruse LOD processing
		cur_object->materials[i].max_size= max2f(max2f(cur_object->materials[i].max_x-cur_object->materials[i].min_x, cur_object->materials[i].max_y-cur_object->materials[i].min_y), cur_object->materials[i].max_z-cur_object->materials[i].min_z);

		cur_object->min_x = min2f(cur_object->min_x, cur_object->materials[i].min_x);
		cur_object->min_y = min2f(cur_object->min_y, cur_object->materials[i].min_y);
		cur_object->min_z = min2f(cur_object->min_z, cur_object->materials[i].min_z);
		cur_object->max_x = max2f(cur_object->max_x, cur_object->materials[i].max_x);
		cur_object->max_y = max2f(cur_object->max_y, cur_object->materials[i].max_y);
		cur_object->max_z = max2f(cur_object->max_z, cur_object->materials[i].max_z);
		cur_object->max_size = max2f(cur_object->max_size, cur_object->materials[i].max_size);

		cur_object->materials[i].triangles_indices_index = indices_size*SDL_SwapLE32(material.index) + index_pointer;
		cur_object->materials[i].triangles_indices_count = SDL_SwapLE32(material.count);
		cur_object->materials[i].triangles_indices_min = SDL_SwapLE32(material.triangles_min_index);
		cur_object->materials[i].triangles_indices_max = SDL_SwapLE32(material.triangles_max_index);

		file_pos += SDL_SwapLE32(material_size);

		el_seek(file, file_pos, SEEK_SET);

	}
	el_close(file);

	LOG_DEBUG_OLD("Building vertex buffers for e3d file '%s'.",
		cur_object->file_name);

	//Generate the buffers
	glGenBuffersARB(1, &cur_object->vertex_vbo);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB,
		cur_object->vertex_vbo);
	glBufferDataARB(GL_ARRAY_BUFFER_ARB,
		cur_object->vertex_no * cur_object->vertex_layout->size,
		cur_object->vertex_data, GL_STATIC_DRAW_ARB);
#ifndef	MAP_EDITOR
	free(cur_object->vertex_data);
	cur_object->vertex_data = 0;
#endif	//MAP_EDITOR
		
	glGenBuffersARB(1, &cur_object->indices_vbo);
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
		cur_object->indices_vbo);
	glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
		cur_object->index_no * indices_size,
		cur_object->indices, GL_STATIC_DRAW_ARB);
#ifndef	MAP_EDITOR
	free(cur_object->indices);
	cur_object->indices = 0;
#endif	//MAP_EDITOR
				
	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);

#ifndef	MAP_EDITOR
	LOG_DEBUG_OLD("Adding e3d file '%s' to cache.",
		cur_object->file_name);

	cache_adj_size(cache_e3d, mem_size, cur_object);
#endif	//MAP_EDITOR
	return cur_object;
}