Пример #1
0
	//	Draw the icons into the window
	//
	void Container::draw_icons(void)
	{
		Busy dummy;
		for (size_t i=0; i<icon_list.size(); ++i)
			icon_list[i]->update_highlight();
		if ((mouse_over_icon >= 0) && ((size_t)mouse_over_icon < icon_list.size()))
			icon_list[mouse_over_icon]->set_highlight(true);
		float uoffset = 31.0/256.0, voffset = 31.0/256.0;
#ifdef	NEW_TEXTURES
		bind_texture(icons_text);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(icons_text);
		voffset *= -1;
#endif	/* NEW_TEXTURES */
		glColor3f(1.0f,1.0f,1.0f);
		glBegin(GL_QUADS);
		for (size_t i=0; i<icon_list.size(); ++i)
		{
			std::pair<float, float> uv = icon_list[i]->get_uv();
			draw_2d_thing( uv.first, uv.second, uv.first+uoffset, uv.second+voffset, i*get_icon_size(), 0, i*get_icon_size()+(get_icon_size()-1), get_icon_size() );
		}
		glEnd();
		if (show_help_text && (mouse_over_icon >= 0) && ((size_t)mouse_over_icon < icon_list.size()))
			show_help(icon_list[mouse_over_icon]->get_help_message(), get_icon_size()*(mouse_over_icon+1)+2, 10);
		mouse_over_icon = -1;
	}
Пример #2
0
void get_and_set_particle_texture_id (int i)
{
#ifdef	NEW_TEXTURES
    bind_texture(particle_textures[i]);
#else	/* NEW_TEXTURES */
    get_and_set_texture_id(particle_textures[i]);
#endif	/* NEW_TEXTURES */
}
Пример #3
0
void draw_string_small(int x, int y,const unsigned char * our_string,int max_lines)
{
	//int displayed_font_x_size=SMALL_FONT_X_LEN;
	//int displayed_font_y_size=SMALL_FONT_Y_LEN;

	unsigned char cur_char;
	int i;
	int cur_x,cur_y;
	int current_lines=0;

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
	glAlphaFunc(GL_GREATER,0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
	while(1)
		{
			cur_char=our_string[i];
			if(!cur_char)
				{
					break;
				}
			else if(cur_char=='\n')
				{
					cur_y+=SMALL_FONT_Y_LEN;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}

			cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, SMALL_FONT_X_LEN, SMALL_FONT_Y_LEN);

			i++;
		}


	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #4
0
void draw_console_pic(int which_texture)
{
#ifdef	NEW_TEXTURES
	bind_texture(which_texture);

	glColor3f(1.0f,1.0f,1.0f);
	glBegin(GL_QUADS);
	//draw the texture

	glTexCoord2f(0.0f, 0.0f);
	glVertex3i(0,0,0);

	glTexCoord2f(0.0f, 1.0f);
	glVertex3i(0,window_height,0);

	glTexCoord2f(1.0f, 1.0f);
	glVertex3i(window_width,window_height,0);

	glTexCoord2f(1.0f, 0.0f);
	glVertex3i(window_width,0,0);

	glEnd();
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(which_texture);

	glColor3f(1.0f,1.0f,1.0f);
	glBegin(GL_QUADS);
	//draw the texture

	glTexCoord2f(0.0f,1.0f);
	glVertex3i(0,0,0);

	glTexCoord2f(0.0f,0.0f);
	glVertex3i(0,window_height,0);

	glTexCoord2f(1.0f,0.0f);
	glVertex3i(window_width,window_height,0);

	glTexCoord2f(1.0f,1.0f);
	glVertex3i(window_width,0,0);

	glEnd();
#endif	/* NEW_TEXTURES */
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #5
0
void draw_string_zoomed(int x, int y,const unsigned char * our_string,int max_lines, float text_zoom)
{
	float displayed_font_x_size=11.0*text_zoom;
	float displayed_font_y_size=18.0*text_zoom;

	unsigned char cur_char;
	int i;
	int cur_x,cur_y;
	int current_lines=0;

   	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
    glAlphaFunc(GL_GREATER,0.1f);
	get_and_set_texture_id(font_text);

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
	while(1)
		{
			cur_char=our_string[i];
			// watch for special characters
			if(!cur_char)	// end of line
				{
					break;
				}
			else if (cur_char == '\n')	// newline
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}

			cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size);

			i++;
		}


    glEnd();
	glDisable(GL_ALPHA_TEST);

}
Пример #6
0
void draw_string_small(int x, int y,const unsigned char * our_string,int max_lines)
{
	int displayed_font_x_size=8;
	int displayed_font_y_size=15;

	unsigned char cur_char;
	int i;
	int cur_x,cur_y;
	int current_lines=0;

   	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
    glAlphaFunc(GL_GREATER,0.1f);
	get_and_set_texture_id(font_text);

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
	while(1)
		{
			cur_char=our_string[i];
			if(!cur_char)
				{
					break;
				}
			else if(cur_char=='\n')
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}

			cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size);

			i++;
		}


    glEnd();
	glDisable(GL_ALPHA_TEST);
}
Пример #7
0
void move_tile()
{
	float x_start,y_start;

	x_start=scene_mouse_x-1.5f;
	y_start=scene_mouse_y-1.5f;

	if(!selected_tile)//we have a lake tile
	{
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_LIGHTING);
		glColor3f(0,0.6f,1.0f);
		glBegin(GL_QUADS);
		glVertex3f(x_start,y_start+3, 0.001f);
		glVertex3f(x_start,y_start, 0.001f);
		glVertex3f(x_start+3, y_start,0.001f);
		glVertex3f(x_start+3, y_start+3,0.001f);
		glEnd();
		glEnable(GL_LIGHTING);
		glEnable(GL_TEXTURE_2D);
	}
	else
	{
#ifdef	NEW_TEXTURES
		bind_texture(tile_list[selected_tile]);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(tile_list[selected_tile]);
#endif	/* NEW_TEXTURES */
		glBegin(GL_QUADS);

 		glTexCoord2f(0, 0.0f);
		glVertex3f(x_start,y_start+3, 0.001f);
		glTexCoord2f(0, 1.0f);
		glVertex3f(x_start,y_start, 0.001f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(x_start+3, y_start,0.001f);
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(x_start+3, y_start+3,0.001f);
		glEnd();
	}

}
Пример #8
0
void display_image(_image *i)
{
	glColor4f(1.0f,1.0f,1.0f,0.5f);
#ifdef	NEW_TEXTURES
	bind_texture(i->texture);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(i->texture);
#endif	/* NEW_TEXTURES */
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.05f);
	glBegin(GL_QUADS);
		glTexCoord2f(i->u[0],i->v[1]); 	glVertex2i(i->x,i->y+i->h);
		glTexCoord2f(i->u[1],i->v[1]);	glVertex2i(i->x+i->w,i->y+i->h);
		glTexCoord2f(i->u[1],i->v[0]);	glVertex2i(i->x+i->w,i->y);
		glTexCoord2f(i->u[0],i->v[0]);	glVertex2i(i->x,i->y);
	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #9
0
void weather_render_lightning()
{
	if (lightning_falling)
	{
		const float *tex_coords = lightnings_defs[lightning_type].coords;
		float size = lightning_sky_position[2]*0.5*(tex_coords[2]-tex_coords[0])/(tex_coords[3]-tex_coords[1]);
		float dx = size*cosf(-rz*M_PI/180.0);
		float dy = size*sinf(-rz*M_PI/180.0);

		glPushAttrib(GL_ENABLE_BIT);
		glDisable(GL_LIGHTING);
		glDisable(GL_FOG);
		glEnable(GL_COLOR_MATERIAL);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);

#ifdef	NEW_TEXTURES
		bind_texture(lightnings_defs[lightning_type%lightnings_defs_count].texture);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(lightnings_defs[lightning_type%lightnings_defs_count].texture);
#endif	/* NEW_TEXTURES */
 
		glColor4fv(lightning_color);
		glBegin(GL_QUADS);
		glTexCoord2f(tex_coords[0], tex_coords[1]);
		glVertex3f(lightning_position[0]-dx, lightning_position[1]-dy, 0.0);
		glTexCoord2f(tex_coords[2], tex_coords[1]);
		glVertex3f(lightning_position[0]+dx, lightning_position[1]+dy, 0.0);
		glTexCoord2f(tex_coords[2], tex_coords[3]);
		glVertex3f(lightning_sky_position[0]+dx, lightning_sky_position[1]+dy, lightning_sky_position[2]);
		glTexCoord2f(tex_coords[0], tex_coords[3]);
		glVertex3f(lightning_sky_position[0]-dx, lightning_sky_position[1]-dy, lightning_sky_position[2]);
		glEnd();
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glPopAttrib();
	}
}
Пример #10
0
int display_storage_handler(window_info * win)
{
	int i;
	int n=0;
	int pos;

	have_storage_list = 0;	//We visited storage, so we may have changed something

	glColor3f(0.77f, 0.57f, 0.39f);
	glEnable(GL_TEXTURE_2D);
	
	for(i=pos=vscrollbar_get_pos(storage_win,STORAGE_SCROLLBAR_CATEGORIES); i<no_storage_categories && storage_categories[i].id!=-1 && i<pos+STORAGE_CATEGORIES_DISPLAY; i++,n++){
		draw_string_small(20, 20+n*13, (unsigned char*)storage_categories[i].name,1);
	}
	if(storage_text[0]){
		if (strcmp(storage_text, last_storage_text) != 0) {
			safe_strncpy(last_storage_text, storage_text, sizeof(last_storage_text));
			put_small_text_in_box ((Uint8 *)storage_text, strlen(storage_text), win->len_x - 18*2, wrapped_storage_text);
		}
		draw_string_small(18, 220, (unsigned char*)wrapped_storage_text, 2);
	}

	glColor3f(1.0f,1.0f,1.0f);
	for(i=pos=6*vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_ITEMS); i<pos+36 && i<no_storage;i++){
		GLfloat u_start, v_start, u_end, v_end;
		int x_start, x_end, y_start, y_end;
		int cur_item;
		GLuint this_texture;

		if(!storage_items[i].quantity)continue;
		cur_item=storage_items[i].image_id%25;
#ifdef	NEW_TEXTURES
		get_item_uv(cur_item, &u_start, &v_start, &u_end, &v_end);
#else	/* NEW_TEXTURES */
		u_start=0.2f*(cur_item%5);
		u_end=u_start+(float)50/255;
		v_start=(1.0f+((float)50/255)/255.0f)-((float)50/255*(cur_item/5));
		v_end=v_start-(float)50/255;
#endif	/* NEW_TEXTURES */
		
		this_texture=get_items_texture(storage_items[i].image_id/25);

#ifdef	NEW_TEXTURES
		if (this_texture != -1)
		{
			bind_texture(this_texture);
		}
#else	/* NEW_TEXTURES */
		if(this_texture!=-1) get_and_set_texture_id(this_texture);
#endif	/* NEW_TEXTURES */

		x_start=(i%6)*32+161;
		x_end=x_start+31;
		y_start=((i-pos)/6)*32+10;
		y_end=y_start+31;

		glBegin(GL_QUADS);
		draw_2d_thing(u_start,v_start,u_end,v_end,x_start,y_start,x_end,y_end);
		glEnd();
	}

	if(cur_item_over!=-1 && mouse_in_window(win->window_id, mouse_x, mouse_y) == 1){
		char str[20];
		Uint16 item_id = storage_items[cur_item_over].id;
		int image_id = storage_items[cur_item_over].image_id;
		if (show_item_desc_text && item_info_available() && (get_item_count(item_id, image_id) == 1))
			show_help(get_item_description(item_id, image_id), 0, win->len_y + 10);

		if (active_storage_item!=storage_items[cur_item_over].pos) {
			safe_snprintf(str, sizeof(str), "%d",storage_items[cur_item_over].quantity);
			show_help(str,mouse_x-win->pos_x-(strlen(str)/2)*8,mouse_y-win->pos_y-14);
		}
	}
	
	// Render the grid *after* the images. It seems impossible to code
	// it such that images are rendered exactly within the boxes on all 
	// cards
	glDisable(GL_TEXTURE_2D);
	
	glColor3f(0.77f, 0.57f, 0.39f);
	
	glBegin(GL_LINE_LOOP);
		glVertex2i(10,  10);
		glVertex2i(10,  202);
		glVertex2i(130, 202);
		glVertex2i(130, 10);
	glEnd();

	glBegin(GL_LINE_LOOP);
		glVertex2i(10, 212);
		glVertex2i(10, 262);
		glVertex2i(392, 262);
		glVertex2i(392, 212);
	glEnd();
	
	if (view_only_storage)
	{
		Uint32 currentticktime = SDL_GetTicks();
		if (currentticktime < drop_fail_time)
			drop_fail_time = 0; 				/* trap wrap */
		if ((currentticktime - drop_fail_time) < 250)
			glColor3f(0.8f,0.2f,0.2f);			/* flash red if tried to drop into */
		else
			glColor3f(0.37f, 0.37f, 0.39f);		/* otherwise draw greyed out */
	}

	rendergrid(6, 6, 160, 10, 32, 32);
	glEnable(GL_TEXTURE_2D);

	glColor3f(1.0f,1.0f,1.0f);
	if(active_storage_item >= 0) {
		/* Draw the active item's quantity on top of everything else. */
		for(i = pos = 6*vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_ITEMS); i < pos+36 && i < no_storage; i++) {
			if(storage_items[i].pos == active_storage_item) {
				if (storage_items[i].quantity) {
					char str[20];
					int x = (i%6)*32+161;

					safe_snprintf(str, sizeof(str), "%d", storage_items[i].quantity);
					if(x > 353) {
						x = 321;
					}
					show_help(str, x, ((i-pos)/6)*32+18);
				}
				break;
			}
		}
	}
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE

	return 1;
}
Пример #11
0
int display_book_handler(window_info *win)
{
	int x=32,i,p;
	char str[20];
	book *b=win->data;
	
	if(!b) {
		toggle_window(book_win);
		return 1;
	}
	switch(b->type){
		case 1:
#ifdef	NEW_TEXTURES
			bind_texture(paper1_text);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(paper1_text);
#endif	/* NEW_TEXTURES */
			break;
		case 2:
#ifdef	NEW_TEXTURES
			bind_texture(book1_text);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(book1_text);
#endif	/* NEW_TEXTURES */
			break;
	}
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f,1.0f); glVertex3i(0,0,0);
		glTexCoord2f(0.0f,0.0f); glVertex3i(0,win->len_y-20,0);
		glTexCoord2f(1.0f,0.0f); glVertex3i(win->len_x,win->len_y-20,0);
		glTexCoord2f(1.0f,1.0f); glVertex3i(win->len_x,0,0);
	glEnd();
	glPushMatrix();
	if(b->type==1)
		glTranslatef(15,25,0);
	else if(b->type==2)
		glTranslatef(30,15,0);
	display_book(b, b->type);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0,win->len_y-18,0);
	book_mouse_y-=(win->len_y-18);
	x=10;
	if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>10 && book_mouse_x<(get_string_width((unsigned char*)"<-")*11.0f/12.0f)){
		glColor3f(0.95f, 0.76f, 0.52f);
		draw_string(10,-2,(unsigned char*)"<-",0);
		
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
	} else if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>win->len_x-33 && book_mouse_x<win->len_x-33+(get_string_width((unsigned char*)"->")*11.0f/12.0f)){
		glColor3f(0.95f, 0.76f, 0.52f);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
		
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(10,-2,(unsigned char*)"<-",0);
	} else {
		glColor3f(0.77f,0.59f, 0.38f);
		draw_string(10,-2,(unsigned char*)"<-",0);
		draw_string(win->len_x-33,-2,(unsigned char*)"->",0);
	}
	if(b->type==1) {
		x=50;
		p=b->active_page-5;
		if(p>=0){
			safe_snprintf(str,sizeof(str),"%d",p+1);

			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=100;
		p=b->active_page-2;
		if(p>=0){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=win->len_x-120;
		p=b->active_page+2;
		if(p<b->no_pages){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
		x=win->len_x-70;
		p=b->active_page+5;
		if(p<b->no_pages){
			safe_snprintf(str,sizeof(str),"%d",p+1);
			
			if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
				glColor3f(0.95f, 0.76f, 0.52f);
				draw_string(x,0,(unsigned char*)str,0);
				glColor3f(0.77f,0.59f, 0.38f);
			} else 
				draw_string(x,0,(unsigned char*)str,0);
		}
	} else if(b->type==2) {
		x=win->len_x/2-60;
		for(i=1;i<5;i++){
			p=b->active_page-i*b->type;
			if(p>=0){
				safe_snprintf(str,sizeof(str),"%d",p+1);
				
				if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
					glColor3f(0.95f, 0.76f, 0.52f);
					draw_string(x,0,(unsigned char*)str,0);
					glColor3f(0.77f,0.59f, 0.38f);
				} else
					draw_string(x,0,(unsigned char*)str,0);
			}
			x-=40;
		}
		x=win->len_x/2+50;
		for(i=1;i<5;i++){
			p=b->active_page+i*b->type;
			if(p<b->no_pages){
				safe_snprintf(str,sizeof(str),"%d",p+1);
				
				if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>x && book_mouse_x<x+(get_string_width((unsigned char*)str)*11.0f/12.0f)){
					glColor3f(0.95f, 0.76f, 0.52f);
					draw_string(x,0,(unsigned char*)str,0);
					glColor3f(0.77f,0.59f, 0.38f);
				} else
					draw_string(x,0,(unsigned char*)str,0);
			}
			x+=40;
		}
	}
	
	if(book_mouse_y>0 && book_mouse_y<18 && book_mouse_x>win->len_x/2-15 && book_mouse_x<win->len_x/2+15)
		glColor3f(0.95f, 0.76f, 0.52f);
	
	draw_string(win->len_x/2-15,0,(unsigned char*)"[X]",0);
	glPopMatrix();
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	return 1;
}
Пример #12
0
void draw_window_alphaborder(window_info *win) {
	int w = win->len_x, h= win->len_y; // width, height

	if (!alpha_border_tex) {
#ifdef	NEW_TEXTURES
		alpha_border_tex = load_texture_cached("textures/alphaborder.dds", tt_image);
#else	/* NEW_TEXTURES */
		alpha_border_tex= load_texture_cache_deferred("textures/alphaborder.bmp", 0);
#endif	/* NEW_TEXTURES */
		if (!alpha_border_tex) return;
	}
	
	glColor3fv(win->back_color);
	glBegin(GL_LINE_LOOP);
	glVertex3i(0, 0, 0);
	glVertex3i(w, 0, 0);
	glVertex3i(w, h, 0);
	glVertex3i(0, h, 0);
	glEnd();

	// The higher the alpha value (a=r+g+b/3) in the border texture,
	// the darker the shadow
	glEnable(GL_BLEND);
	glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);
	
	glEnable(GL_TEXTURE_2D);
#ifdef	NEW_TEXTURES
	bind_texture(alpha_border_tex);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(alpha_border_tex);
#endif	/* NEW_TEXTURES */

	glBegin(GL_QUADS);

	/*
	 * 
	 *       r===============================i
	 *     11|                               |99
	 *    111|                               |999
	 *    111|                               |999
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222|                               |888
	 *    222'-------------------------------'888
	 *    333444555555555555555555555555555666777
	 *    333444555555555555555555555555555666777
	 *     3344455555555555555555555555555566677
	 *        4455555555555555555555555555566 
	 */

#ifdef	NEW_TEXTURES
	glTexCoord2f(1.0f, 1.0f); glVertex2i( - 8,    0);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0,    0);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0,   16);
	glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8,   16);

	glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8,   16);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0,   16);
	glTexCoord2f(0.1f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(0.1f, 1.0f); glVertex2i( - 8, h   );

	glTexCoord2f(0.5f, 1.0f); glVertex2i( - 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0, h+16);
	glTexCoord2f(1.0f, 1.0f); glVertex2i( - 8, h+16);

	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(0.5f, 0.0f); glVertex2i(   8, h   );
	glTexCoord2f(1.0f, 0.0f); glVertex2i(   8, h+16);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0, h+16);

	glTexCoord2f(0.1f, 0.0f); glVertex2i(   8, h   );
	glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h   );
	glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h+16);
	glTexCoord2f(0.1f, 1.0f); glVertex2i(   8, h+16);

	glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );
	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   , h+16);
	glTexCoord2f(1.0f, 0.0f); glVertex2i(w- 8, h+16);

	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );
	glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8, h   );
	glTexCoord2f(1.0f, 1.0f); glVertex2i(w+ 8, h+16);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   , h+16);

	glTexCoord2f(0.1f, 0.5f); glVertex2i(w   ,   16);
	glTexCoord2f(0.1f, 1.0f); glVertex2i(w+ 8,   16);
	glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );

	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   ,    0);
	glTexCoord2f(1.0f, 1.0f); glVertex2i(w+ 8,    0);
	glTexCoord2f(0.5f, 1.0f); glVertex2i(w+ 8,   16);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   ,   16);
#else	/* NEW_TEXTURES */
	glTexCoord2f(1.0f, 0.0f); glVertex2i( - 8,    0);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0,    0);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0,   16);
	glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8,   16);

	glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8,   16);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0,   16);
	glTexCoord2f(0.1f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(0.1f, 0.0f); glVertex2i( - 8, h   );

	glTexCoord2f(0.5f, 0.0f); glVertex2i( - 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0, h+16);
	glTexCoord2f(1.0f, 0.0f); glVertex2i( - 8, h+16);

	glTexCoord2f(0.5f, 0.5f); glVertex2i(   0, h   );
	glTexCoord2f(0.5f, 1.0f); glVertex2i(   8, h   );
	glTexCoord2f(1.0f, 1.0f); glVertex2i(   8, h+16);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(   0, h+16);

	glTexCoord2f(0.1f, 1.0f); glVertex2i(   8, h   );
	glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h   );
	glTexCoord2f(0.5f, 0.0f); glVertex2i(w- 8, h+16);
	glTexCoord2f(0.1f, 0.0f); glVertex2i(   8, h+16);

	glTexCoord2f(0.5f, 1.0f); glVertex2i(w- 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );
	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   , h+16);
	glTexCoord2f(1.0f, 1.0f); glVertex2i(w- 8, h+16);

	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );
	glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8, h   );
	glTexCoord2f(1.0f, 0.0f); glVertex2i(w+ 8, h+16);
	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   , h+16);

	glTexCoord2f(0.1f, 0.5f); glVertex2i(w   ,   16);
	glTexCoord2f(0.1f, 0.0f); glVertex2i(w+ 8,   16);
	glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8, h   );
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   , h   );

	glTexCoord2f(1.0f, 0.5f); glVertex2i(w   ,    0);
	glTexCoord2f(1.0f, 0.0f); glVertex2i(w+ 8,    0);
	glTexCoord2f(0.5f, 0.0f); glVertex2i(w+ 8,   16);
	glTexCoord2f(0.5f, 0.5f); glVertex2i(w   ,   16);
#endif	/* NEW_TEXTURES */

	glEnd();
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_BLEND);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #13
0
void draw_minimap_title_bar(window_info *win)
{
#ifdef	NEW_TEXTURES
	float u_first_start= (float)31/255;
	float u_first_end = 0.0f;
	float v_first_start = (float)160/255;
	float v_first_end = (float)175/255;

	float u_last_start = 0.0f;
	float u_last_end = (float)31/255;
	float v_last_start = (float)160/255;
	float v_last_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float u_first_start= (float)31/255;
	float u_first_end= 0;
	float v_first_start= 1.0f-(float)160/255;
	float v_first_end= 1.0f-(float)175/255;

	float u_last_start= 0;
	float u_last_end= (float)31/255;
	float v_last_start= 1.0f-(float)160/255;
	float v_last_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	int close_button_x = win->len_x/2 + 32 - 1;

	glPushMatrix();

	glColor3f(1.0f,1.0f,1.0f);
	
#ifdef	NEW_TEXTURES
	bind_texture(icons_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(icons_text);
#endif	/* NEW_TEXTURES */
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER,0.03f);
	glEnable(GL_TEXTURE_2D);

	glBegin(GL_QUADS);

	glTexCoord2f(u_first_end, v_first_start);
	glVertex3i(win->len_x/2-32, ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_first_end, v_first_end);
	glVertex3i(win->len_x/2-32, 0, 0);
	glTexCoord2f(u_first_start, v_first_end);
	glVertex3i(win->len_x/2, 0, 0);
	glTexCoord2f(u_first_start, v_first_start);
	glVertex3i(win->len_x/2, ELW_TITLE_HEIGHT, 0);

	glTexCoord2f(u_last_end, v_last_start);
	glVertex3i(win->len_x/2, ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_last_end, v_last_end);
	glVertex3i(win->len_x/2, 0, 0);
	glTexCoord2f(u_last_start, v_last_end);
	glVertex3i(win->len_x/2+32, 0, 0);
	glTexCoord2f(u_last_start, v_last_start);
	glVertex3i(win->len_x/2+32, ELW_TITLE_HEIGHT, 0);
	
	glEnd();
	glDisable(GL_ALPHA_TEST);
	glDisable(GL_TEXTURE_2D);

	//draw the X background
	glColor3f(0.156f,0.078f,0.0f);
	glBegin(GL_POLYGON);
		glVertex2f(close_button_x + ELW_TITLE_HEIGHT, ELW_TITLE_HEIGHT);
		glVertex2f(close_button_x, ELW_TITLE_HEIGHT);
		glVertex2f(close_button_x, 0);
		glVertex2f(close_button_x + ELW_TITLE_HEIGHT, 0);
	glEnd();
	//draw the rectngle
	glColor3f(win->line_color[0],win->line_color[1],win->line_color[2]);
	glBegin(GL_LINE_STRIP);
		glVertex2i(close_button_x + ELW_TITLE_HEIGHT-2 - gx_adjust, ELW_TITLE_HEIGHT-1 - gy_adjust);
		glVertex2i(close_button_x + 1 - gx_adjust, ELW_TITLE_HEIGHT-1 - gy_adjust);
		glVertex2i(close_button_x + 1 - gx_adjust, 2 - gy_adjust);
		glVertex2i(close_button_x + ELW_TITLE_HEIGHT-2 - gx_adjust, 2 - gy_adjust);
		glVertex2i(close_button_x + ELW_TITLE_HEIGHT-2 - gx_adjust, ELW_TITLE_HEIGHT-1 - gy_adjust);
	glEnd();
	//draw the X
	glLineWidth(2.0f);
	glBegin(GL_LINES);
		glVertex2i(close_button_x + 3, 4);
		glVertex2i(close_button_x + ELW_TITLE_HEIGHT-3, ELW_TITLE_HEIGHT-4);
		glVertex2i(close_button_x + ELW_TITLE_HEIGHT-3, 4);
		glVertex2i(close_button_x + 3, ELW_TITLE_HEIGHT-4);
	glEnd();

	glLineWidth(1.0f);

	glPopMatrix();
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #14
0
int display_ground_items_handler(window_info *win)
{
	char str[80];
	char my_str[10];
	int i;
	static Uint8 resizing = 0;
	int yoffset = get_window_scroll_pos(win->window_id);

	/* if resizing wait until we stop */
	if (win->resized)
		resizing = 1;
	/* once we stop, snap the window to the new grid size */
	else if (resizing)
	{
		int new_width = (ground_items_grid_cols+1)*GRIDSIZE;
		int new_rows = (win->len_y+GRIDSIZE/2)/GRIDSIZE;
		int max_rows = (ITEMS_PER_BAG + ground_items_grid_cols - 1) / ground_items_grid_cols;
		resizing = 0;
		resize_window (win->window_id, new_width, ((new_rows > max_rows) ?max_rows :new_rows)*GRIDSIZE);
		yoffset = get_window_scroll_pos(win->window_id);
	}

	glEnable(GL_TEXTURE_2D);

	// write "get all" in the "get all" box :)
	strap_word(get_all_str,my_str);
	glColor3f(0.77f,0.57f,0.39f);
	draw_string_small(win->len_x-(GRIDSIZE-5), ELW_BOX_SIZE+3+yoffset, (unsigned char*)my_str, 2);

	glColor3f(1.0f,1.0f,1.0f);
	//ok, now let's draw the objects...
	for(i=ITEMS_PER_BAG-1; i>=0; --i) {
		if(ground_item_list[i].quantity > 0) {
			float u_start,v_start,u_end,v_end;
			int this_texture,cur_item,cur_pos;
			int x_start,x_end,y_start,y_end;

			//get the UV coordinates.
			cur_item=ground_item_list[i].image_id%25;
#ifdef	NEW_TEXTURES
			get_item_uv(cur_item, &u_start, &v_start, &u_end,
				&v_end);
#else	/* NEW_TEXTURES */
			u_start=0.2f*(cur_item%5);
			u_end=u_start+(float)50/256;
			v_start=(1.0f+((float)50/256)/256.0f)-((float)50/256*(cur_item/5));
			v_end=v_start-(float)50/256;
#endif	/* NEW_TEXTURES */

			//get the x and y
			cur_pos=i;
			x_start=GRIDSIZE*(cur_pos%ground_items_grid_cols)+1;
			x_end=x_start+32;
			y_start=GRIDSIZE*(cur_pos/ground_items_grid_cols);
			y_end=y_start+32;

			//get the texture this item belongs to
			this_texture=get_items_texture(ground_item_list[i].image_id/25);

#ifdef	NEW_TEXTURES
			bind_texture(this_texture);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(this_texture);
#endif	/* NEW_TEXTURES */

			glBegin(GL_QUADS);
				draw_2d_thing(u_start,v_start,u_end,v_end,x_start,y_start,x_end,y_end);
			glEnd();

			safe_snprintf(str,sizeof(str),"%i",ground_item_list[i].quantity);
			draw_string_small_shadowed(x_start,y_end-(i&1?22:12),(unsigned char*)str,1,1.0f,1.0f,1.0f,0.0f,0.0f,0.0f);
		}
	}

	// Render the grid *after* the images. It seems impossible to code
	// it such that images are rendered exactly within the boxes on all
	// cards
	glDisable(GL_TEXTURE_2D);

	glColor3f(0.77f,0.57f,0.39f);
	/* if a full grid render in one go */
	if (ground_items_grid_cols*ground_items_grid_rows == ITEMS_PER_BAG)
		rendergrid(ground_items_grid_cols,ground_items_grid_rows,0,0,GRIDSIZE,GRIDSIZE);
	/* otherwise don't render the extra slots */
	else
	{
		int remainder = ITEMS_PER_BAG - (ground_items_grid_cols*(ground_items_grid_rows-1));
		rendergrid(ground_items_grid_cols,ground_items_grid_rows-1,0,0,GRIDSIZE,GRIDSIZE);
		rendergrid(remainder, 1, 0, GRIDSIZE*(ground_items_grid_rows-1), GRIDSIZE, GRIDSIZE);
	}

	glBegin(GL_LINE_LOOP);

		// draw the "get all" box
		glVertex2i(win->len_x, ELW_BOX_SIZE+yoffset);
		glVertex2i(win->len_x-GRIDSIZE, ELW_BOX_SIZE+yoffset);
		glVertex2i(win->len_x-GRIDSIZE, ELW_BOX_SIZE+GRIDSIZE+yoffset);
		glVertex2i(win->len_x, ELW_BOX_SIZE+GRIDSIZE+yoffset);

	glEnd();
	glEnable(GL_TEXTURE_2D);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	return 1;
}
Пример #15
0
void draw_2d_object(obj_2d *object_id)
{
	float render_x_start,render_y_start,u_start,v_start,u_end,v_end;
	float x_pos,y_pos,z_pos;
	float x_rot,y_rot,z_rot;
	float x_size,y_size;
	int object_type;
	obj_2d_def *obj_def_pointer;

	if(!object_id->display) return;	// not currently on the map, ignore it

	obj_def_pointer=object_id->obj_pointer;

	u_start=obj_def_pointer->u_start;
	u_end=obj_def_pointer->u_end;
 	v_start=obj_def_pointer->v_start;
	v_end=obj_def_pointer->v_end;
	x_size=obj_def_pointer->x_size;
	y_size=obj_def_pointer->y_size;
	render_x_start=-x_size/2.0f;

	object_type=obj_def_pointer->object_type;
	if(object_type==GROUND)render_y_start=-y_size/2;
	else	render_y_start=0;

	glPushMatrix();//we don't want to affect the rest of the scene

	x_pos=object_id->x_pos;
	y_pos=object_id->y_pos;
	z_pos=object_id->z_pos;
	if (object_type != PLANT)
	{
		glMultMatrixf(object_id->matrix);
		z_rot = object_id->z_rot;
	}
	else
	{
		glTranslatef (x_pos, y_pos, 0);

		x_rot = object_id->x_rot + 90;
		y_rot = object_id->y_rot;
		z_rot=-rz;
		glRotatef(z_rot, 0.0f, 0.0f, 1.0f);
		glRotatef(x_rot, 1.0f, 0.0f, 0.0f);
		glRotatef(y_rot, 0.0f, 1.0f, 0.0f);
	}

#ifdef	NEW_TEXTURES
	bind_texture(obj_def_pointer->texture_id);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(obj_def_pointer->texture_id);
#endif	/* NEW_TEXTURES */

	if (dungeon || (!clouds_shadows && !use_shadow_mapping))
		{
			glBegin(GL_QUADS);

			glTexCoord2f(u_start,v_start);
			glVertex3f(render_x_start,render_y_start,z_pos);

			glTexCoord2f(u_start,v_end);
			glVertex3f(render_x_start,render_y_start+y_size,z_pos);

			glTexCoord2f(u_end,v_end);
			glVertex3f(render_x_start+x_size,render_y_start+y_size,z_pos);

			glTexCoord2f(u_end,v_start);
			glVertex3f(render_x_start+x_size,render_y_start,z_pos);
			
	    		glEnd();
		}
	else
		{
			float m,x,y,x1,y1;
			float cos_m,sin_m;

			glBegin(GL_QUADS);

			m=(-z_rot)*M_PI/180;
			cos_m=cos(m);
			sin_m=sin(m);

			x=render_x_start;
			y=render_y_start;
			x1=x*cos_m+y*sin_m;
			y1=y*cos_m-x*sin_m;
			x1=x_pos+x1;
			y1=y_pos+y1;

			ELglMultiTexCoord2fARB(base_unit,u_start,v_start);
			ELglMultiTexCoord2fARB(detail_unit,x1/texture_scale
								 +clouds_movement_u,y1/texture_scale
								 +clouds_movement_v);
			glVertex3f(x,y,z_pos);

			x=render_x_start;
			y=render_y_start+y_size;
			x1=x*cos_m+y*sin_m;
			y1=y*cos_m-x*sin_m;
			x1=x_pos+x1;
			y1=y_pos+y1;

			ELglMultiTexCoord2fARB(base_unit,u_start,v_end);
			ELglMultiTexCoord2fARB(detail_unit,x1/texture_scale
								 +clouds_movement_u,y1/texture_scale
								 +clouds_movement_v);
			glVertex3f(x,y,z_pos);

			x=render_x_start+x_size;
			y=render_y_start+y_size;
			x1=x*cos_m+y*sin_m;
			y1=y*cos_m-x*sin_m;
			x1=x_pos+x1;
			y1=y_pos+y1;

			ELglMultiTexCoord2fARB(base_unit,u_end,v_end);
			ELglMultiTexCoord2fARB(detail_unit,x1/texture_scale
								 +clouds_movement_u,y1/texture_scale
								 +clouds_movement_v);
			glVertex3f(x,y,z_pos);

			x=render_x_start+x_size;
			y=render_y_start;
			x1=x*cos_m+y*sin_m;
			y1=y*cos_m-x*sin_m;
			x1=x_pos+x1;
			y1=y_pos+y1;


			ELglMultiTexCoord2fARB(base_unit,u_end,v_start);
			ELglMultiTexCoord2fARB(detail_unit,x1/texture_scale
								 +clouds_movement_u,y1/texture_scale
								 +clouds_movement_v);
			glVertex3f(x,y,z_pos);
    		glEnd();
		}
	glPopMatrix();//restore the scene
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #16
0
void draw_ingame_string(float x, float y,const unsigned char * our_string,
						int max_lines,int big)
{
	float u_start,u_end,v_start,v_end;
	int col,row;
	float displayed_font_x_size;
	float displayed_font_y_size;

	float displayed_font_x_width;
	int font_x_size=FONT_X_SPACING;
	int font_y_size=FONT_Y_SPACING;
	int	font_bit_width, ignored_bits;

	unsigned char cur_char;
	int chr;
	int i;
	float cur_x,cur_y;
	int current_lines=0;

	if(big)
		{
			displayed_font_x_size=0.17*zoom_level*name_zoom/3.0;
			displayed_font_y_size=0.25*zoom_level*name_zoom/3.0;
		}
	else
		{
			displayed_font_x_size=SMALL_INGAME_FONT_X_LEN*zoom_level*name_zoom/3.0;
			displayed_font_y_size=SMALL_INGAME_FONT_Y_LEN*zoom_level*name_zoom/3.0;
		}


   	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
    glAlphaFunc(GL_GREATER,0.1f);
	get_and_set_texture_id(font_text);

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
	while(1)
		{
			cur_char=our_string[i];
			if(!cur_char)
				{
					break;
				}
			else if(cur_char=='\n')
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}
			else if(cur_char >127 && cur_char<=127+c_grey4)
				{
					glEnd();	//Ooops - NV bug fix!!
				}
			chr=find_font_char(cur_char);
			if(chr >= 0)
				{
					col=chr/FONT_CHARS_PER_LINE;
					row=chr%FONT_CHARS_PER_LINE;


					font_bit_width=get_font_width(chr);
					displayed_font_x_width=((float)font_bit_width)*displayed_font_x_size/12.0;
					ignored_bits=(12-font_bit_width)/2;	// how many bits on each side of the char are ignored?
					if(ignored_bits < 0)ignored_bits=0;

					//now get the texture coordinates
					u_start=(float)(row*font_x_size+ignored_bits)/256.0f;
					u_end=(float)(row*font_x_size+font_x_size-7-ignored_bits)/256.0f;
					v_start=(float)1.0f-(1+col*font_y_size)/256.0f;
					v_end=(float)1.0f-(col*font_y_size+font_y_size-1)/256.0f;
					//v_end=(float)1.0f-(col*font_y_size+font_y_size-2)/256.0f;

					glTexCoord2f(u_start,v_start);
					glVertex3f(cur_x,0,cur_y+displayed_font_y_size);
		
					glTexCoord2f(u_start,v_end);
					glVertex3f(cur_x,0,cur_y);

					glTexCoord2f(u_end,v_end);
					glVertex3f(cur_x+displayed_font_x_width,0,cur_y);

					glTexCoord2f(u_end,v_start);
					glVertex3f(cur_x+displayed_font_x_width,0,cur_y+displayed_font_y_size);
					

					//cur_x+=displayed_font_x_size;
					cur_x+=displayed_font_x_width;
				}
			else if(cur_char >127 && cur_char<=127+c_grey4)
				{
					glBegin(GL_QUADS);	//Ooops - NV bug fix!!
				}

			i++;
		}

    glEnd();
	glDisable(GL_ALPHA_TEST);
}
Пример #17
0
void draw_messages (int x, int y, text_message *msgs, int msgs_size, Uint8 filter, int msg_start, int offset_start, int cursor, int width, int height, float text_zoom, select_info* select)
{
	float displayed_font_x_size = DEFAULT_FONT_X_LEN * text_zoom;
	float displayed_font_y_size = DEFAULT_FONT_Y_LEN * text_zoom;

	float selection_red = 255 / 255.0f;
	float selection_green = 162 / 255.0f;
	float selection_blue = 0;

	unsigned char cur_char;
	int i;
	int imsg, ichar;
	int cur_x, cur_y;
	int cursor_x = x-1, cursor_y = y-1;
	unsigned char ch;
	int cur_line = 0;
	int cur_col = 0;
	unsigned char last_color_char = 0;
	int in_select = 0;

	imsg = msg_start;
	ichar = offset_start;
	if (msgs[imsg].data == NULL || msgs[imsg].deleted) return;

	if (width < displayed_font_x_size || height < displayed_font_y_size)
		// no point in trying
		return;

#ifndef MAP_EDITOR2
	if (filter != FILTER_ALL)
	{
		// skip all messages of the wrong channel
		while (1)
		{
			if (skip_message(&msgs[imsg], filter))
			{
				ichar = 0;
				if (++imsg >= msgs_size) imsg = 0;
				if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted)
					// nothing to draw
					return;
			}
			else
			{
				break;
			}
		}
		if (msgs[imsg].data == NULL || msgs[imsg].deleted) return;
	}
#endif //! MAP_EDITOR2

	ch = msgs[imsg].data[ichar];
	if (!is_color (ch))
	{
		// search backwards for the last color
		for (i = ichar-1; i >= 0; i--)
		{
			ch = msgs[imsg].data[i];
			if (is_color (ch))
			{
				find_font_char (ch);
				last_color_char = ch;
				break;
			}
		}

		if (i < 0)
		{
			// no color character found, try the message color
			if (msgs[imsg].r >= 0)
				glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b);
		}
	}

 	glEnable (GL_ALPHA_TEST);	// enable alpha filtering, so we have some alpha key
	glAlphaFunc (GL_GREATER, 0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i = 0;
	cur_x = x;
	cur_y = y;
	glBegin (GL_QUADS);
	while (1)
	{
		if (i == cursor)
		{
			cursor_x = cur_x;
			cursor_y = cur_y;
			if (cursor_x - x > width - displayed_font_x_size)
			{
				cursor_x = x;
				cursor_y = cur_y + displayed_font_y_size;
			}

		}

		cur_char = msgs[imsg].data[ichar];
		// watch for special characters
		if (cur_char == '\0')
		{
			// end of message
			if (++imsg >= msgs_size) {
				imsg = 0;
			}
#ifndef MAP_EDITOR2
			if (filter != FILTER_ALL)
			{
				// skip all messages of the wrong channel
				while (skip_message (&msgs[imsg], filter))
				{
					if (++imsg >= msgs_size) imsg = 0;
					if (msgs[imsg].data == NULL || imsg == msg_start) break;
				}
			}
#endif
			if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted) break;
			rewrap_message (&msgs[imsg], text_zoom, width, NULL);
			ichar = 0;
			last_color_char = 0;
		}

		if (select != NULL && select->lines && select->lines[cur_line].msg == -1)
		{
			select->lines[cur_line].msg = imsg;
			select->lines[cur_line].chr = ichar;
		}

		if (cur_char == '\n' || cur_char == '\r' || cur_char == '\0')
		{
			// newline
			cur_y += displayed_font_y_size;
			if (cur_y - y > height - displayed_font_y_size) break;
			cur_x = x;
			if (cur_char != '\0') ichar++;
			i++;
			cur_line++;
			cur_col = 0;
			continue;
		}

		if (pos_selected(imsg, ichar, select))
		{
			if (!in_select)
			{
				glColor3f (selection_red, selection_green, selection_blue);
				in_select = 1;
			}
		}
		else
		{
			if (in_select)
			{
				if (last_color_char)
					find_font_char (last_color_char);
				else if (msgs[imsg].r < 0)
					find_font_char (to_color_char (c_grey1));
				else
					glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b);

				in_select = 0;
			}
		}

		if (is_color (cur_char))
		{
			last_color_char = cur_char;
			if (in_select)
			{
				// don't draw color characters in a selection
				i++;
				ichar++;
				continue;
			}
		}

		cur_x += draw_char_scaled (cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size);
		cur_col++;

		ichar++;
		i++;
		if (cur_x - x > width - displayed_font_x_size)
		{
			// ignore rest of this line, but keep track of
			// color characters
			while (1)
			{
				ch = msgs[imsg].data[ichar];
				if (ch == '\0' || ch == '\n' || ch == '\r')
					break;
				if (is_color (ch))
					last_color_char = ch;
				ichar++;
				i++;
			}
		}
	}

	if (cursor_x >= x && cursor_y >= y && cursor_y - y <= height - displayed_font_y_size)
	{
		draw_char_scaled ('_', cursor_x, cursor_y, displayed_font_x_size, displayed_font_y_size);
	}

	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #18
0
int display_options_handler(window_info *win)
{
	int i = 0, y[2], x[2];
	option_struct * cur;
	x[0]=8;
	x[1]=188;
	y[0]=35;
	y[1]=35;
	get_and_set_texture_id(icons_text);
	glBegin(GL_QUADS);
	for(;i<options.no;i++)
		{
			cur=options.option[i];
			if (cur->type!=NONE)
				{
					if (*(cur->data_1)>0)
						{
							if (
								(cur->type==OPTION && *(cur->data_2))
										||
								(cur->type==VIDEO_MODE && video_modes[*(cur->data_2)-1].selected)
							   )
								{
									draw_2d_thing(lit_gem_u_start, lit_gem_v_start, lit_gem_u_end, lit_gem_v_end,
											x[cur->column], y[cur->column], x[cur->column]+30, y[cur->column?1:0]+16);
								}
							else
								{
									draw_2d_thing(unlit_gem_u_start, unlit_gem_v_start, unlit_gem_u_end, unlit_gem_v_end,
											x[cur->column], y[cur->column], x[cur->column]+30, y[cur->column]+16);
								}
						}
					else
						{
							draw_2d_thing(broken_gem_u_start,broken_gem_v_start,broken_gem_u_end,broken_gem_v_end,
									x[cur->column], y[cur->column], x[cur->column]+30, y[cur->column]+16);
						}
				}
			y[cur->column]+=20;
		}
	glEnd();
	
	draw_string(55,10,opt_strings.str,1);//Options
	draw_string(225,10,opt_strings.desc,1);//Video mode

	x[0]=45;
	x[1]=225;
	y[0]=35;
	y[1]=35;
	
	for(i=0;i<options.no;i++)
		{
			cur=options.option[i];
			if(cur->type!=NONE)
				{
					draw_string(x[cur->column],y[cur->column],cur->name,1);
				}
			y[cur->column]+=20;
		}

	glColor4f(0.0f, 1.0f, 0.0f, 0.0f);
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_LINES);
	glVertex3i(0, win->len_y-40,0);
	glVertex3i(win->len_x, win->len_y-40,0);
	glEnd();
	glEnable(GL_TEXTURE_2D);
	draw_string_small(4,win->len_y-35,options_help_text,2);
	return 1;
}
Пример #19
0
void draw_new_char_screen()
{

	float selected_bar_u_start=(float)0/256;
	float selected_bar_v_start=1.0f-(float)0/256;

	float selected_bar_u_end=(float)174/256;
	float selected_bar_v_end=1.0f-(float)28/256;


	float unselected_bar_u_start=(float)0/256;
	float unselected_bar_v_start=1.0f-(float)40/256;

	float unselected_bar_u_end=(float)170/256;
	float unselected_bar_v_end=1.0f-(float)63/256;

	check_for_input();

	//see if we have to load a model (male or female)
	if(!any_model)
		{
			our_model=add_actor_interface(race+male,skin_color,hair_color,shirt_color,pants_color,boots_color,head);
			any_model=1;//we have an actor loaded
		}

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,270,skin_str,1);
	if(skin_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,270,"<<",1);
	if(skin_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,270,">>",1);

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,290,hair_str,1);
	if(hair_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,290,"<<",1);
	if(hair_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,290,">>",1);

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,310,shirt_str,1);
	if(shirt_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,310,"<<",1);
	if(shirt_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,310,">>",1);

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,330,pants_str,1);
	if(pants_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,330,"<<",1);
	if(pants_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,330,">>",1);

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,350,boots_str,1);
	if(boots_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,350,"<<",1);
	if(boots_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,350,">>",1);

	glColor3f(1.0f,1.0f,1.0f);
	draw_string(10,370,head_str,1);
	if(head_b)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(90,370,"<<",1);
	if(head_f)glColor3f(0.3f,1.0f,0.3f);
	else glColor3f(1.0f,0.7f,0.0f);
	draw_string(120,370,">>",1);

	glColor3f(1.0f,0.2f,0.2f);
	draw_string(530,280,gender_str,1);

	if(male==1)glColor3f(0.0f,0.5f,1.0f);
	else glColor3f(1.0f,1.0f,1.0f);
	draw_string(530,300,male_str,1);

	if(male!=1)glColor3f(0.0f,0.5f,1.0f);
	else glColor3f(1.0f,1.0f,1.0f);
	draw_string(530,320,female_str,1);
	glColor3f(1.0f,1.0f,1.0f);

	glColor3f(1.0f,0.2f,0.2f);
	draw_string(530,360,"Race",1);

	if(race==race_human)glColor3f(0.0f,0.5f,1.0f);
	else glColor3f(1.0f,1.0f,1.0f);
	draw_string(530,380,human_str,1);
	glColor3f(1.0f,1.0f,1.0f);

	if(race==race_elf)glColor3f(0.0f,0.5f,1.0f);
	else glColor3f(1.0f,1.0f,1.0f);
	draw_string(530,400,elf_str,1);
	glColor3f(1.0f,1.0f,1.0f);

	if(race==race_dwarf)glColor3f(0.0f,0.5f,1.0f);
	else glColor3f(1.0f,1.0f,1.0f);
	draw_string(530,420,dwarf_str,1);
	glColor3f(1.0f,1.0f,1.0f);

	//draw the player frame
	glDisable(GL_TEXTURE_2D);
	glBegin(GL_QUADS);
	glColor4f(0.4f,0.4f,0.4f,0.5f);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_end,0);

	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_end,0);
	glEnd();

	glColor3f(0.2f,0.2f,0.2f);
	glBegin(GL_LINES);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_end,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start,actor_creation_menu_y_start,0);

	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_start,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_end+200,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_end,0);
	glVertex3i(actor_creation_menu_x_start+200,actor_creation_menu_y_start,0);

	glEnd();
	glEnable(GL_TEXTURE_2D);

	//draw the player
	glEnable(GL_DEPTH_TEST);
	draw_interface_actor(our_model,150.0f,300,250,0,90.0f,0.0f, 0.0f);

	draw_interface_actor(our_model,150.0f,500,250,0,270.0f,0.0f, -180.0f);
	glDisable(GL_DEPTH_TEST);

	//now start putting the dialogue boxes.
	get_and_set_texture_id(login_screen_menus);
	glColor3f(1.0f,1.0f,1.0f);
	glBegin(GL_QUADS);

	//username box
	if(username)
		draw_2d_thing(selected_bar_u_start,selected_bar_v_start,
					  selected_bar_u_end,selected_bar_v_end,10,30,200,58);
	else
		draw_2d_thing(unselected_bar_u_start,unselected_bar_v_start,
					  unselected_bar_u_end,unselected_bar_v_end,10,30,200,58);

	//password box
	if(password)
		draw_2d_thing(selected_bar_u_start,selected_bar_v_start,
					  selected_bar_u_end,selected_bar_v_end,10,88,200,116);
	else
		draw_2d_thing(unselected_bar_u_start,unselected_bar_v_start,
					  unselected_bar_u_end,unselected_bar_v_end,10,88,200,116);

	//confirm box
	if(confirm_pass)
		draw_2d_thing(selected_bar_u_start,selected_bar_v_start,
					  selected_bar_u_end,selected_bar_v_end,10,146,200,174);
	else
		draw_2d_thing(unselected_bar_u_start,unselected_bar_v_start,
					  unselected_bar_u_end,unselected_bar_v_end,10,146,200,174);

	//done_button button
	if(done_button)
		draw_2d_thing(done_button_selected_start_u,done_button_selected_start_v,
					  done_button_selected_end_u,done_button_selected_end_v,10,
					  200,97,235);
	else
		draw_2d_thing(done_button_unselected_start_u,done_button_unselected_start_v,
					  done_button_unselected_end_u,done_button_unselected_end_v,10,
					  200,97,235);

	//back button
	if(back)
		draw_2d_thing(back_selected_start_u,back_selected_start_v,
					  back_selected_end_u,back_selected_end_v,110,
					  200,197,235);
	else
		draw_2d_thing(back_unselected_start_u,back_unselected_start_v,
					  back_unselected_end_u,back_unselected_end_v,110,
					  200,197,235);

	glEnd();

	//now, draw the text 'labels'
	glColor3f(0.0f,1.0f,0.5f);
	draw_string(60,10,login_username_str,1);

	draw_string(60,68,login_password_str,1);

	draw_string(20,126,confirm_password,1);

	//put the username, pass, and conf pass user text
	glColor3f(0.0f,0.5f,1.0f);
	draw_string(15,97,display_pass_str,1);

	draw_string(15,154,display_conf_pass_str,1);

	draw_string(15,38,user_str,1);

	glColor3f(1.0f,0.0f,0.0f);
	//print the current error, if any
	draw_string(10,400,create_char_error_str,1);



}
Пример #20
0
int display_encyclopedia_handler(window_info *win)
{
	_Text *t=Page[currentpage].T.Next;
	_Image *i=Page[currentpage].I.Next;
	int j;

	j=vscrollbar_get_pos(encyclopedia_win, encyclopedia_scroll_id);

	while(t)
	{
		int ylen=(t->size)?18:15;
		int xlen=strlen(t->text)*((t->size)?11:8);

		// Bounds Check the Text
		if((t->y-j > 0) && (t->y-j < encyclopedia_menu_y_len-20 ))
		{
			if(t->ref)
				{
					//draw a line
					glColor3f(0.5,0.5,0.5);
					glDisable(GL_TEXTURE_2D);
					glBegin(GL_LINES);
					glVertex3i(t->x+4,t->y+ylen-j,0);
					glVertex3i(t->x+4+xlen-8,t->y+ylen-j,0);
					glEnd();
					glEnable(GL_TEXTURE_2D);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
				}
			if(t->size)
				{
					if(t->ref && mouse_x>(t->x+win->cur_x) && mouse_x<(t->x+xlen+win->cur_x) && mouse_y>(t->y+win->cur_y-j) && mouse_y<(t->y+ylen+win->cur_y-j))
					glColor3f(0.3,0.6,1.0);
					else
					glColor3f(t->r,t->g,t->b);
					draw_string(t->x,t->y-j,(unsigned char*)t->text,1);
				}
			else
				{
					if(t->ref && mouse_x>(t->x+win->cur_x) && mouse_x<(t->x+xlen+win->cur_x) && mouse_y>(t->y+win->cur_y-j) && mouse_y<(t->y+ylen+win->cur_y-j))
					glColor3f(0.3,0.6,1.0);
					else
					glColor3f(t->r,t->g,t->b);
					draw_string_small(t->x,t->y-j,(unsigned char*)t->text,1);
				}
		}
		// No next line?
		if(!t->Next)
			break;

		t=t->Next;
	}

	glColor3f(1.0f,1.0f,1.0f);
	while(i){
		// Bounds Check the Text
		if((i->y-j > 0) && (i->yend-j < encyclopedia_menu_y_len-40 ))
		{
			if(i->mouseover==1)
			{
				i=i->Next;
				continue;
			}
			if(mouse_x>(i->x+win->cur_x) && mouse_x<(win->cur_x+i->xend) && mouse_y>(i->y+win->cur_y-j) && mouse_y<(win->cur_y-j+i->yend))
			{
				if(i->Next!=NULL)
				{
					if(i->Next->mouseover==1)
						i=i->Next;
				}
			}
#ifdef	NEW_TEXTURES
			bind_texture(i->id);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(i->id);
#endif	/* NEW_TEXTURES */
			glBegin(GL_QUADS);
			draw_2d_thing(i->u, i->v, i->uend, i->vend,i->x, i->y-j,i->xend,i->yend-j);
			glEnd();
		}
		i=i->Next;

	}

#ifdef ENCYCL_NAVIGATION
	if (repeat_search && last_search != NULL)
	{
		find_page(last_search, NULL);
		repeat_search = 0;
	}
	if (show_cm_help)
	{
		show_help(cm_encycl_help_str, 0, win->len_y+10);
		show_cm_help = 0;
	}
#endif

	return 1;
}
Пример #21
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
}
Пример #22
0
int	draw_window_title(window_info *win)
{
	float u_first_start= (float)31/255;
	float u_first_end= 0;
#ifdef	NEW_TEXTURES
	float v_first_start = (float)160/255;
	float v_first_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_first_start= 1.0f-(float)160/255;
	float v_first_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	float u_middle_start= (float)32/255;
	float u_middle_end= (float)63/255;
#ifdef	NEW_TEXTURES
	float v_middle_start = (float)160/255;
	float v_middle_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_middle_start= 1.0f-(float)160/255;
	float v_middle_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	float u_last_start= 0;
	float u_last_end= (float)31/255;
#ifdef	NEW_TEXTURES
	float v_last_start = (float)160/255;
	float v_last_end = (float)175/255;
#else	/* NEW_TEXTURES */
	float v_last_start= 1.0f-(float)160/255;
	float v_last_end= 1.0f-(float)175/255;
#endif	/* NEW_TEXTURES */

	if((win->flags&ELW_TITLE_BAR) == ELW_TITLE_NONE)	return 0;

	glColor3f(1.0f,1.0f,1.0f);
	//ok, now draw that shit...

#ifdef	NEW_TEXTURES
	bind_texture(icons_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(icons_text);
#endif	/* NEW_TEXTURES */
	glEnable(GL_ALPHA_TEST);
    glAlphaFunc(GL_GREATER,0.03f);
	glBegin(GL_QUADS);

	glTexCoord2f(u_first_end, v_first_start);
	glVertex3i(0, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_first_end, v_first_end);
	glVertex3i(0, 0, 0);
	glTexCoord2f(u_first_start, v_first_end);
	glVertex3i(32, 0, 0);
	glTexCoord2f(u_first_start, v_first_start);
	glVertex3i(32, -ELW_TITLE_HEIGHT, 0);

	// draw one streched out cell to the proper size
	glTexCoord2f(u_middle_end, v_middle_start);
	glVertex3i(32, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_middle_end, v_middle_end);
	glVertex3i(32, 0, 0);
	glTexCoord2f(u_middle_start, v_middle_end);
	glVertex3i(win->len_x-32, 0, 0);
	glTexCoord2f(u_middle_start, v_middle_start);
	glVertex3i(win->len_x-32, -ELW_TITLE_HEIGHT, 0);

	glTexCoord2f(u_last_end, v_last_start);
	glVertex3i(win->len_x-32, -ELW_TITLE_HEIGHT, 0);
	glTexCoord2f(u_last_end, v_last_end);
	glVertex3i(win->len_x-32, 0, 0);
	glTexCoord2f(u_last_start, v_last_end);
	glVertex3i(win->len_x, 0, 0);
	glTexCoord2f(u_last_start, v_last_start);
	glVertex3i(win->len_x, -ELW_TITLE_HEIGHT, 0);

	glEnd();
	glDisable(GL_ALPHA_TEST);

	// draw the name of the window
	if(win->flags&ELW_TITLE_NAME)
		{
			int	len;
			const unsigned char* name = (const unsigned char*) win->window_name;

			glEnable(GL_TEXTURE_2D);
			glColor3f(win->border_color[0],win->border_color[1],win->border_color[2]);
			// center text
			len = (get_string_width (name) * 8) / 12;
			draw_string_small((win->len_x-len)/2, -ELW_TITLE_HEIGHT, name, 1);
		}

	return 1;
}
Пример #23
0
void draw_3d_object_detail(object3d * object_id, Uint32 material_index, Uint32 use_lightning,
	Uint32 use_textures, Uint32 use_extra_textures)
{
	e3d_vertex_data* vertex_layout;
	Uint8 * data_ptr;

	// check for having to load the arrays
	load_e3d_detail_if_needed(object_id->e3d_data);

	CHECK_GL_ERRORS();
	//also, update the last time this object was used
	object_id->last_acessed_time = cur_time;

	//debug

	if (object_id->self_lit && (!is_day || dungeon) && use_lightning) 
	{
		glColor3fv(object_id->color);
	}

	CHECK_GL_ERRORS();

	glPushMatrix();//we don't want to affect the rest of the scene

	glMultMatrixf(object_id->matrix);

	CHECK_GL_ERRORS();

	if (!dungeon && (clouds_shadows || use_shadow_mapping) && use_extra_textures)
	{
		VECTOR4 plane;

		ELglActiveTextureARB(detail_unit);
		memcpy(plane, object_id->clouds_planes[0], sizeof(VECTOR4));
		plane[3] += clouds_movement_u;
		glTexGenfv(GL_S, GL_EYE_PLANE, plane);
		memcpy(plane, object_id->clouds_planes[1], sizeof(VECTOR4));
		plane[3] += clouds_movement_v;
		glTexGenfv(GL_T, GL_EYE_PLANE, plane);
		ELglActiveTextureARB(base_unit);
	}

	// watch for a change
	if (object_id->e3d_data != cur_e3d)
	{
		if ((cur_e3d != NULL) && (use_compiled_vertex_array))
		{
			ELglUnlockArraysEXT();
		}

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ARRAY_BUFFER_ARB,
				object_id->e3d_data->vertex_vbo);
			data_ptr = 0;
		}
		else
		{
			data_ptr = object_id->e3d_data->vertex_data;
		}

		vertex_layout = object_id->e3d_data->vertex_layout;

		if ((vertex_layout->normal_count > 0) && use_lightning)
		{
			glEnableClientState(GL_NORMAL_ARRAY);
			glNormalPointer(vertex_layout->normal_type, vertex_layout->size,
				data_ptr + vertex_layout->normal_offset);
		}
		else
		{
			glDisableClientState(GL_NORMAL_ARRAY);
			glNormal3f(0.0f, 0.0f, 1.0f);
		}

		if (use_textures)
		{
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(vertex_layout->texture_count, vertex_layout->texture_type,
				vertex_layout->size, data_ptr + vertex_layout->texture_offset);
		}
		else
		{
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}

		glVertexPointer(vertex_layout->position_count, vertex_layout->position_type,
			vertex_layout->size, data_ptr + vertex_layout->position_offset);

		if (use_vertex_buffers)
		{
			ELglBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,
				object_id->e3d_data->indices_vbo);
		}

		// lock this new one
		if (use_compiled_vertex_array)
		{
			ELglLockArraysEXT(0, object_id->e3d_data->vertex_no);
		}
		// gather statistics
		if (object_id->e3d_data != cur_e3d)
		{
#ifdef  DEBUG
			if ((cur_e3d_count > 0) && (cur_e3d != NULL))
			{
				e3d_count++;
				e3d_total += cur_e3d_count;
			}
			cur_e3d_count = 0;
#endif    //DEBUG
			cur_e3d = object_id->e3d_data;
		}
	}
#ifdef  DEBUG
	cur_e3d_count++;
#endif  //DEBUG

	if (use_textures)
	{
		glEnable(GL_TEXTURE_2D);
#ifdef	NEW_TEXTURES
		bind_texture(object_id->e3d_data->materials[material_index].texture);
#else	/* NEW_TEXTURES */
		get_and_set_texture_id(object_id->e3d_data->materials[material_index].texture);
#endif	/* NEW_TEXTURES */
	}
	else
	{
		glDisable(GL_TEXTURE_2D);		
	}


	if (use_draw_range_elements && ELglDrawRangeElementsEXT)
		ELglDrawRangeElementsEXT(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_min,
			object_id->e3d_data->materials[material_index].triangles_indices_max,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);
	else
		glDrawElements(GL_TRIANGLES,
			object_id->e3d_data->materials[material_index].triangles_indices_count,
			object_id->e3d_data->index_type,
			object_id->e3d_data->materials[material_index].triangles_indices_index);

	glPopMatrix();//restore the scene
	CHECK_GL_ERRORS();

	//OK, let's check if our mouse is over...
#ifdef MAP_EDITOR2
	if (selected_3d_object == -1 && read_mouse_now && mouse_in_sphere(object_id->x_pos, object_id->y_pos, object_id->z_pos, object_id->e3d_data->radius))
		anything_under_the_mouse(object_id->id, UNDER_MOUSE_3D_OBJ);
#endif
}
Пример #24
0
void draw_ortho_ingame_string(float x, float y,float z, const unsigned char * our_string,
						int max_lines, float font_x_scale, float font_y_scale)
{
	float u_start,u_end,v_start,v_end;
	int col,row;
	float displayed_font_x_size;
	float displayed_font_y_size;

	float displayed_font_x_width;
#ifndef SKY_FPV_OPTIONAL
	int font_x_size=FONT_X_SPACING;
	int font_y_size=FONT_Y_SPACING;
#endif // not SKY_FPV_OPTIONAL
	int	font_bit_width, ignored_bits;

	unsigned char cur_char;
	int chr;
	int i;
	float cur_x,cur_y;
	int current_lines=0;

#ifndef SKY_FPV_OPTIONAL
	/*
	if(big)
		{
			displayed_font_x_size=0.17*zoom_level*name_zoom/3.0;
			displayed_font_y_size=0.25*zoom_level*name_zoom/3.0;
		}
	else
		{
			displayed_font_x_size=SMALL_INGAME_FONT_X_LEN*zoom_level*name_zoom/3.0;
			displayed_font_y_size=SMALL_INGAME_FONT_Y_LEN*zoom_level*name_zoom/3.0;
		}
	*/
#endif // not SKY_FPV_OPTIONAL
	displayed_font_x_size=font_x_scale*name_zoom*12.0;
	displayed_font_y_size=font_y_scale*name_zoom*12.0;

	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
	glAlphaFunc(GL_GREATER,0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
#ifndef SKY_FPV_OPTIONAL
	while(1)
		{
			cur_char=our_string[i];
			if(!cur_char)
				{
					break;
				}
			else if(cur_char=='\n')
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}
			else if (is_color (cur_char))
				{
					glEnd();	//Ooops - NV bug fix!!
				}
			chr=find_font_char(cur_char);
			if(chr >= 0)
				{
					col=chr/FONT_CHARS_PER_LINE;
					row=chr%FONT_CHARS_PER_LINE;


					font_bit_width=get_font_width(chr);
					displayed_font_x_width=((float)font_bit_width)*displayed_font_x_size/12.0;
					ignored_bits=(12-font_bit_width)/2;	// how many bits on each side of the char are ignored?
					if(ignored_bits < 0)ignored_bits=0;

					//now get the texture coordinates
					u_start=(float)(row*font_x_size+ignored_bits)/256.0f;
					u_end=(float)(row*font_x_size+font_x_size-7-ignored_bits)/256.0f;
#ifdef NEW_TEXTURES
					v_start=(float)(1+col*font_y_size)/256.0f;
					v_end=(float)(col*font_y_size+font_y_size-1)/256.0f;
#else
					v_start=(float)1.0f-(1+col*font_y_size)/256.0f;
					v_end=(float)1.0f-(col*font_y_size+font_y_size-1)/256.0f;
#endif //NEW_TEXTURES
					//v_end=(float)1.0f-(col*font_y_size+font_y_size-2)/256.0f;

					glTexCoord2f(u_start,v_start);
					glVertex3f(cur_x,cur_y+displayed_font_y_size,z);

					glTexCoord2f(u_start,v_end);
					glVertex3f(cur_x,cur_y,z);

					glTexCoord2f(u_end,v_end);
					glVertex3f(cur_x+displayed_font_x_width,cur_y,z);

					glTexCoord2f(u_end,v_start);
					glVertex3f(cur_x+displayed_font_x_width,cur_y+displayed_font_y_size,z);


					//cur_x+=displayed_font_x_size;
					cur_x+=displayed_font_x_width;
				}
			else if (is_color (cur_char))
				{
					glBegin(GL_QUADS);	//Ooops - NV bug fix!!
				}

#else // SKY_FPV_OPTIONAL
	while(1){
		cur_char=our_string[i];
		if(!cur_char){
			break;
		} else if(cur_char=='\n'){
			cur_y+=displayed_font_y_size;
			cur_x=x;
#endif // SKY_FPV_OPTIONAL
			i++;
#ifdef SKY_FPV_OPTIONAL
			current_lines++;
			if(current_lines>=max_lines)break;
			continue;
		} else if (is_color (cur_char)){
			glEnd();	//Ooops - NV bug fix!!
			glBegin(GL_QUADS);
		}
		chr=find_font_char(cur_char);
		if(chr >= 0){
			col=chr/FONT_CHARS_PER_LINE;
			row=chr%FONT_CHARS_PER_LINE;

			font_bit_width=get_font_width(chr);
			displayed_font_x_width=((float)font_bit_width)*displayed_font_x_size/12.0;
			ignored_bits=(12-font_bit_width)/2;	// how many bits on each side of the char are ignored?
			if(ignored_bits < 0)ignored_bits=0;

			//now get the texture coordinates
			u_start=(float)(row*FONT_X_SPACING+ignored_bits)/256.0f;
			u_end=(float)(row*FONT_X_SPACING+FONT_X_SPACING-7-ignored_bits)/256.0f;
#ifdef NEW_TEXTURES
			v_start=(float)(1+col*FONT_Y_SPACING)/256.0f;
			v_end=(float)(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#else
			v_start=(float)1.0f-(1+col*FONT_Y_SPACING)/256.0f;
			v_end=(float)1.0f-(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#endif //NEW_TEXTURES

			glTexCoord2f(u_start,v_start);
			glVertex3f(cur_x,cur_y+displayed_font_y_size,z);

			glTexCoord2f(u_start,v_end);
			glVertex3f(cur_x,cur_y,z);

			glTexCoord2f(u_end,v_end);
			glVertex3f(cur_x+displayed_font_x_width,cur_y,z);

			glTexCoord2f(u_end,v_start);
			glVertex3f(cur_x+displayed_font_x_width,cur_y+displayed_font_y_size,z);

			cur_x+=displayed_font_x_width;
		} else if(is_color (cur_char)){
			glEnd();	//Ooops - NV bug fix!!
			glBegin(GL_QUADS);
#endif // SKY_FPV_OPTIONAL
		}
#ifdef SKY_FPV_OPTIONAL
	i++;
	}
#endif // SKY_FPV_OPTIONAL

	glEnd();
	glDisable(GL_ALPHA_TEST);
}

void draw_ingame_string(float x, float y,const unsigned char * our_string,
						int max_lines, float font_x_scale, float font_y_scale)
{
	float u_start,u_end,v_start,v_end;
	int col,row;
	float displayed_font_x_size;
	float displayed_font_y_size;

	float displayed_font_x_width;
#ifndef SKY_FPV_OPTIONAL
	//int font_x_size=FONT_X_SPACING;
	//int font_y_size=FONT_Y_SPACING;
#endif // not SKY_FPV_OPTIONAL
	int	font_bit_width, ignored_bits;

	unsigned char cur_char;
	int chr;
	int i;
	float cur_x,cur_y;
	int current_lines=0;
#ifdef SKY_FPV_OPTIONAL
	double model[16], proj[16],hx,hy,hz;
	int view[4];

	displayed_font_x_size=font_x_scale*name_zoom*12.0*font_scale;
	displayed_font_y_size=font_y_scale*name_zoom*12.0*font_scale;

	glGetDoublev(GL_MODELVIEW_MATRIX, model);
	glGetDoublev(GL_PROJECTION_MATRIX, proj);
	glGetIntegerv(GL_VIEWPORT, view);
	gluProject((double)x,0.0f,(double)y,model, proj, view, &hx,&hy,&hz);
	glPushMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(view[0],view[2]+view[0],view[1],view[3]+view[1],0.0f,-1.0f);
#endif // SKY_FPV_OPTIONAL

#ifndef SKY_FPV_OPTIONAL
	displayed_font_x_size=font_x_scale*zoom_level*name_zoom/3.0;
	displayed_font_y_size=font_y_scale*zoom_level*name_zoom/3.0;
#endif // not SKY_FPV_OPTIONAL

	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
	glAlphaFunc(GL_GREATER,0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i=0;
#ifndef SKY_FPV_OPTIONAL
	cur_x=x;
	cur_y=y;
#else // SKY_FPV_OPTIONAL
	cur_x=hx;
	cur_y=hy;
#endif // SKY_FPV_OPTIONAL
	glBegin(GL_QUADS);
#ifndef SKY_FPV_OPTIONAL
	while(1)
		{
			cur_char=our_string[i];
			if(!cur_char)
				{
					break;
				}
			else if(cur_char=='\n')
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>=max_lines)break;
					continue;
				}
			else if(is_color (cur_char))
				{
					glEnd();	//Ooops - NV bug fix!!
				}
			chr=find_font_char(cur_char);
			if(chr >= 0)
				{
					col=chr/FONT_CHARS_PER_LINE;
					row=chr%FONT_CHARS_PER_LINE;

					font_bit_width=get_font_width(chr);
					displayed_font_x_width=((float)font_bit_width)*displayed_font_x_size/12.0;
					ignored_bits=(12-font_bit_width)/2;	// how many bits on each side of the char are ignored?
					if(ignored_bits < 0)ignored_bits=0;

					//now get the texture coordinates
					u_start=(float)(row*FONT_X_SPACING+ignored_bits)/256.0f;
					u_end=(float)(row*FONT_X_SPACING+FONT_X_SPACING-7-ignored_bits)/256.0f;
#ifdef NEW_TEXTURES
					v_start=(float)(1+col*FONT_Y_SPACING)/256.0f;
					v_end=(float)(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#else
					v_start=(float)1.0f-(1+col*FONT_Y_SPACING)/256.0f;
					v_end=(float)1.0f-(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#endif //NEW_TEXTURES

					glTexCoord2f(u_start,v_start);
					glVertex3f(cur_x,0,cur_y+displayed_font_y_size);

					glTexCoord2f(u_start,v_end);
					glVertex3f(cur_x,0,cur_y);

					glTexCoord2f(u_end,v_end);
					glVertex3f(cur_x+displayed_font_x_width,0,cur_y);

					glTexCoord2f(u_end,v_start);
					glVertex3f(cur_x+displayed_font_x_width,0,cur_y+displayed_font_y_size);

					cur_x+=displayed_font_x_width;
				}
			else if (is_color (cur_char))
				{
					glBegin(GL_QUADS);	//Ooops - NV bug fix!!
				}
#else // SKY_FPV_OPTIONAL
	while(1){
		cur_char=our_string[i];
		if(!cur_char){
			break;
		}else if(cur_char=='\n'){
			cur_y+=displayed_font_y_size;
			cur_x=hx;
#endif // SKY_FPV_OPTIONAL
			i++;
#ifdef SKY_FPV_OPTIONAL
			current_lines++;
			if(current_lines>=max_lines)break;
			continue;
		}
		else if (is_color (cur_char))
		{
			glEnd();	//Ooops - NV bug fix!!
			glBegin(GL_QUADS);
		}
		chr=find_font_char(cur_char);
		if(chr >= 0){
			col=chr/FONT_CHARS_PER_LINE;
			row=chr%FONT_CHARS_PER_LINE;

			font_bit_width=get_font_width(chr);
			displayed_font_x_width=((float)font_bit_width)*displayed_font_x_size/12.0;
			ignored_bits=(12-font_bit_width)/2;	// how many bits on each side of the char are ignored?
			if(ignored_bits < 0)ignored_bits=0;

			//now get the texture coordinates
			u_start=(float)(row*FONT_X_SPACING+ignored_bits)/256.0f;
			u_end=(float)(row*FONT_X_SPACING+FONT_X_SPACING-7-ignored_bits)/256.0f;
#ifdef NEW_TEXTURES
			v_start=(float)(1+col*FONT_Y_SPACING)/256.0f;
			v_end=(float)(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#else
			v_start=(float)1.0f-(1+col*FONT_Y_SPACING)/256.0f;
			v_end=(float)1.0f-(col*FONT_Y_SPACING+FONT_Y_SPACING-1)/256.0f;
#endif // NEW_TEXTURES

			glTexCoord2f(u_start,v_start);
			glVertex3f(cur_x,cur_y+displayed_font_y_size,0);

			glTexCoord2f(u_start,v_end);
			glVertex3f(cur_x,cur_y,0);

			glTexCoord2f(u_end,v_end);
			glVertex3f(cur_x+displayed_font_x_width,cur_y,0);

			glTexCoord2f(u_end,v_start);
			glVertex3f(cur_x+displayed_font_x_width,cur_y+displayed_font_y_size,0);

			cur_x+=displayed_font_x_width;
		}
		else if (is_color (cur_char))
		{
			glEnd();	//Ooops - NV bug fix!!
			glBegin(GL_QUADS);
#endif // SKY_FPV_OPTIONAL
		}
#ifdef SKY_FPV_OPTIONAL
		i++;
	}
#endif // SKY_FPV_OPTIONAL

	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef SKY_FPV_OPTIONAL
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();

#endif // SKY_FPV_OPTIONAL
}
#endif //!MAP_EDITOR_2
#endif	//ELC



// font handling
int get_font_width(int cur_char)
{
	// ignore unknown characters
	if (cur_char < 0) {
		return 0;
	}
	// return width of character + spacing between chars (supports variable width fonts)
	return (fonts[cur_font_num]->widths[cur_char] + fonts[cur_font_num]->spacing);
}

int get_char_width(unsigned char cur_char)
{
	return get_font_width(get_font_char(cur_char));
}


int get_string_width(const unsigned char *str)
{
	return get_nstring_width(str, strlen((char*)str));
}


int get_nstring_width(const unsigned char *str, int len)
{
	int	i, wdt=0;

	for(i=0; i<len; i++) {
		wdt+= get_char_width(str[i]);
	}

	// adjust to ignore the final spacing
	wdt-= fonts[cur_font_num]->spacing;

	return wdt;
}
Пример #25
0
int draw_string_zoomed_width (int x, int y, const unsigned char * our_string, int max_width, int max_lines, float text_zoom)
{
	float displayed_font_x_size= 11.0*text_zoom;
	float displayed_font_y_size= 18.0*text_zoom;

	unsigned char cur_char;
	int i;
	int cur_x,cur_y;
	int current_lines= 1;

#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	glEnable(GL_ALPHA_TEST);//enable alpha filtering, so we have some alpha key
	glAlphaFunc(GL_GREATER,0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i=0;
	cur_x=x;
	cur_y=y;
	glBegin(GL_QUADS);
	while(1)
		{
			cur_char=our_string[i];
			// watch for special characters
			if(!cur_char)	// end of line
				{
					break;
				}
			else if (cur_char == '\n' || cur_char == '\r')	// newline
				{
					cur_y+=displayed_font_y_size;
					cur_x=x;
					i++;
					current_lines++;
					if(current_lines>max_lines)break;
					continue;
				}
			else if (cur_x+displayed_font_x_size-x>=max_width){
				cur_y+=displayed_font_y_size;
				cur_x=x;
				current_lines++;
				if(current_lines>max_lines)break;
			}

			cur_x+=draw_char_scaled(cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size);

			i++;
		}

	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
	return current_lines;
}
Пример #26
0
void weather_render()
{
	int type;
	int i;
	float modelview[16];
	float delta1[3], delta2[3];
	float color1[4], color2[4], light_level[3];

	skybox_get_current_color(color1, skybox_light_ambient);
	skybox_get_current_color(color2, skybox_light_diffuse);

	light_level[0] = 0.5 + (0.2 + color1[0] + color2[0]) * 0.5;
	light_level[1] = 0.5 + (0.2 + color1[1] + color2[1]) * 0.5;
	light_level[2] = 0.5 + (0.2 + color1[2] + color2[2]) * 0.5;

	if (lightning_falling)
	{
		light_level[0] += 0.5 * lightning_color[0];
		light_level[1] += 0.5 * lightning_color[1];
		light_level[2] += 0.5 * lightning_color[2];
	}

	if (light_level[0] > 1.0) light_level[0] = 1.0;
	if (light_level[1] > 1.0) light_level[1] = 1.0;
	if (light_level[2] > 1.0) light_level[2] = 1.0;

    glGetFloatv(GL_MODELVIEW_MATRIX, modelview);
          
	glPushAttrib(GL_ENABLE_BIT);
	glDisable(GL_LIGHTING);
	
	glDisable(GL_ALPHA_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	// we first render the weather that don't use particles
	glEnableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisable(GL_TEXTURE_2D);
	
	for (type = 1; type < MAX_WEATHER_TYPES; ++type)
		if (!weather_defs[type].use_sprites && weather_drops_count[type] > 0)
		{
			glLineWidth(weather_defs[type].size);
			glColor4f(weather_defs[type].color[0]*light_level[0],
					  weather_defs[type].color[1]*light_level[1],
					  weather_defs[type].color[2]*light_level[2],
					  weather_defs[type].color[3]);
			glVertexPointer(3, GL_FLOAT, 0, weather_drops[type]);
	
			for (i = 0; i < weather_drops_count[type]; i += 1000) // to avoid long arrays
			{
				int nb = weather_drops_count[type] - i;
				if (nb > 1000) nb = 1000;
				glDrawArrays(GL_LINES, i, nb);
			}
		}
	
	glLineWidth(1.0);
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	
	// we then render the other precipitations as sprites
    glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), weather_particles_coords);
    glVertexPointer(3, GL_FLOAT, 5*sizeof(float), weather_particles_coords+2);
	for (type = 2; type < MAX_WEATHER_TYPES; ++type)
		if (weather_defs[type].use_sprites && weather_drops_count[type] > 0)
		{
			delta1[0] = weather_defs[type].size*(modelview[0]+modelview[1]);
			delta1[1] = weather_defs[type].size*(modelview[4]+modelview[5]);
			delta1[2] = weather_defs[type].size*(modelview[8]+modelview[9]);
			delta2[0] = weather_defs[type].size*(modelview[0]-modelview[1]);
			delta2[1] = weather_defs[type].size*(modelview[4]-modelview[5]);
			delta2[2] = weather_defs[type].size*(modelview[8]-modelview[9]);
			
			for (i = 0; i < weather_drops_count[type]; ++i)
			{
				const weather_drop *d = &weather_drops[type][i];
                const int j = i*20;
                weather_particles_coords[j+2 ] = d->pos1[0]-delta1[0];
                weather_particles_coords[j+3 ] = d->pos1[1]-delta1[1];
                weather_particles_coords[j+4 ] = d->pos1[2]-delta1[2];
                weather_particles_coords[j+7 ] = d->pos1[0]+delta2[0];
                weather_particles_coords[j+8 ] = d->pos1[1]+delta2[1];
                weather_particles_coords[j+9 ] = d->pos1[2]+delta2[2];
                weather_particles_coords[j+12] = d->pos1[0]+delta1[0];
                weather_particles_coords[j+13] = d->pos1[1]+delta1[1];
                weather_particles_coords[j+14] = d->pos1[2]+delta1[2];
                weather_particles_coords[j+17] = d->pos1[0]-delta2[0];
                weather_particles_coords[j+18] = d->pos1[1]-delta2[1];
                weather_particles_coords[j+19] = d->pos1[2]-delta2[2];
			}

			glColor4f(weather_defs[type].color[0]*light_level[0],
					  weather_defs[type].color[1]*light_level[1],
					  weather_defs[type].color[2]*light_level[2],
					  weather_defs[type].color[3]);
			
#ifdef	NEW_TEXTURES
			bind_texture(weather_defs[type].texture);
#else	/* NEW_TEXTURES */
			get_and_set_texture_id(weather_defs[type].texture);
#endif	/* NEW_TEXTURES */
            glDrawArrays(GL_QUADS, 0, weather_drops_count[type]);
		}

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_BLEND);
	glPopAttrib();
#ifdef OPENGL_TRACE
	CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
Пример #27
0
int display_help_handler(window_info *win)
{
    _Text *t=Page[helppage].T.Next;
    _Image *i=Page[helppage].I.Next;
    int j;
    j=vscrollbar_get_pos(help_win,0);

    while(t) {
        int ylen=(t->size)?18:15;
        int xlen=strlen(t->text)*((t->size)?11:8);

        if((t->y-j > 0) && (t->y-j < help_menu_y_len-20 ))
        {
            if(t->ref)
            {
                //draw a line
                glColor3f(0.5,0.5,0.5);
                glDisable(GL_TEXTURE_2D);
                glBegin(GL_LINES);
                glVertex3i(t->x+4,t->y+ylen-j,0);
                glVertex3i(t->x+4+xlen-8,t->y+ylen-j,0);
                glEnd();
                glEnable(GL_TEXTURE_2D);
#ifdef OPENGL_TRACE
                CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
            }
            if(t->size)
            {
                if(t->ref && mouse_x>(t->x+win->cur_x) && mouse_x<(t->x+xlen+win->cur_x) && mouse_y>(t->y+win->cur_y-j) && mouse_y<(t->y+ylen+win->cur_y-j))
                    glColor3f(0.3,0.6,1.0);
                else
                    glColor3f(t->r,t->g,t->b);
                draw_string(t->x,t->y-j,(unsigned char*)t->text,1);
            }
            else
            {
                if(t->ref && mouse_x>(t->x+win->cur_x) && mouse_x<(t->x+xlen+win->cur_x) && mouse_y>(t->y+win->cur_y-j) && mouse_y<(t->y+ylen+win->cur_y-j))
                    glColor3f(0.3,0.6,1.0);
                else
                    glColor3f(t->r,t->g,t->b);
                draw_string_small(t->x,t->y-j,(unsigned char*)t->text,1);
            }
        }
        t=t->Next;
    }

    glColor3f(1.0f,1.0f,1.0f);
    while(i) {
        if((i->y-j > 0) && (i->yend-j < help_menu_y_len-40 ))
        {
            if(i->mouseover==1)
            {
                i=i->Next;
                continue;
            }
            if(mouse_x>(i->x+win->cur_x) && mouse_x<(win->cur_x+i->xend) && mouse_y>(i->y+win->cur_y-j) && mouse_y<(win->cur_y+i->yend-j))
            {
                if(i->Next!=NULL)
                {
                    if(i->Next->mouseover==1)
                        i=i->Next;
                }
            }
#ifdef	NEW_TEXTURES
            bind_texture(i->id);
#else	/* NEW_TEXTURES */
            get_and_set_texture_id(i->id);
#endif	/* NEW_TEXTURES */
            glBegin(GL_QUADS);
            draw_2d_thing(i->u, i->v, i->uend, i->vend,i->x, i->y-j,i->xend,i->yend-j);
            glEnd();
        }
        i=i->Next;
    }
    return 1;
}
Пример #28
0
void draw_string_zoomed_clipped (int x, int y, const unsigned char* our_string, int cursor_pos, int width, int height, float text_zoom)
{
	float displayed_font_x_size = DEFAULT_FONT_X_LEN * text_zoom;
	float displayed_font_y_size = DEFAULT_FONT_Y_LEN * text_zoom;

	unsigned char cur_char;
	int i;
	int cur_x, cur_y;
	int cursor_x = x-1, cursor_y = y-1;

	if (width < displayed_font_x_size || height < displayed_font_y_size)
		// no point in trying
		return;

	glEnable (GL_ALPHA_TEST);	// enable alpha filtering, so we have some alpha key
	glAlphaFunc (GL_GREATER, 0.1f);
#ifdef	NEW_TEXTURES
	bind_texture(font_text);
#else	/* NEW_TEXTURES */
	get_and_set_texture_id(font_text);
#endif	/* NEW_TEXTURES */

	i = 0;
	cur_x = x;
	cur_y = y;
	glBegin (GL_QUADS);
	while (1)
	{
		if (i == cursor_pos)
		{
			cursor_x = cur_x;
			cursor_y = cur_y;
			if (cursor_x - x > width - displayed_font_x_size)
			{
				cursor_x = x;
				cursor_y = cur_y + displayed_font_y_size;
			}

		}

		cur_char = our_string[i];
		// watch for special characters
		if (!cur_char)
		{
			// end of string
			break;
		}
		else if (cur_char == '\n' || cur_char == '\r')
		{
			// newline
			cur_y += displayed_font_y_size;
			if (cur_y - y > height - displayed_font_y_size) break;
			cur_x = x;
			i++;
			continue;
		}

		cur_x += draw_char_scaled (cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size);

		i++;
		if (cur_x - x > width - displayed_font_x_size)
		{
			// ignore rest of this line
			while (our_string[i] != '\0' && our_string[i] != '\n' && our_string[i] != '\r') i++;
		}
	}

	if (cursor_x >= x && cursor_y >= y && cursor_y - y <= height - displayed_font_y_size)
	{
		draw_char_scaled ('_', cursor_x, cursor_y, displayed_font_x_size, displayed_font_y_size);
	}

	glEnd();
	glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}