示例#1
0
文件: font.c 项目: piaopolar/taisei
void draw_text(Alignment align, float x, float y, const char *text, TTF_Font *font) {
	char *nl;
	char *buf = malloc(strlen(text)+1);
	strcpy(buf, text);
	
	if((nl = strchr(buf, '\n')) != NULL && strlen(nl) > 1) {
		draw_text(align, x, y + 20, nl+1, font);
		*nl = '\0';
	}
		
	Texture *tex = load_text(buf, font);
	
	switch(align) {
	case AL_Center:
		draw_texture_p(x, y, tex);
		break;
	case AL_Left:
		draw_texture_p(x + tex->w/2.0, y, tex);
		break;
	case AL_Right:
		draw_texture_p(x - tex->w/2.0, y, tex);
		break;
	}
		
	free_texture(tex);
	free(buf);
}
示例#2
0
void Petal(Projectile *p, int t) {
	float x = creal(p->args[2]);
	float y = cimag(p->args[2]);
	float z = creal(p->args[3]);
	
	glDisable(GL_CULL_FACE);
	
	glPushMatrix();
	if(p->pos)
		glTranslatef(creal(p->pos), cimag(p->pos),0);
	glRotatef(t*4.0 + cimag(p->args[3]), x, y, z);
		
	if(p->clr)
		glColor4fv((float *)p->clr);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	draw_texture_p(0,0, p->tex);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	
	if(p->clr)
		glColor4f(1,1,1,1);
	glPopMatrix();
	
	glEnable(GL_CULL_FACE);
}
示例#3
0
void draw_stage_menu(MenuData *m) {
	draw_options_menu_bg(m);
	draw_text(AL_Right, (stringwidth(m->title, _fonts.mainmenu) + 10) * (1-m->fade), 30, m->title, _fonts.mainmenu);
	
	glPushMatrix();
	glTranslatef(100, 100 + (((m->ecount * 20 + 290) > SCREEN_W)? min(0, SCREEN_H * 0.7 - 100 - m->drawdata[2]) : 0), 0);
	
	/*
	glPushMatrix();
	glTranslatef(SCREEN_W/2 - 100, m->drawdata[2], 0);
	glScalef(SCREEN_W - 200, 20, 1);
	glColor4f(0,0,0,0.5);
	draw_quad();
	glPopMatrix();
	*/
	
	Texture *bg = get_tex("part/smoke");
	glPushMatrix();
	glTranslatef(m->drawdata[0], m->drawdata[2], 0);
	glScalef(m->drawdata[1]/100.0, 0.2, 1);
	glRotatef(m->frames*2,0,0,1);
	glColor4f(0,0,0,0.5);
	draw_texture_p(0,0,bg);
	glPopMatrix();
	
	MenuEntry *s = &(m->entries[m->cursor]);
	m->drawdata[0] += ((s->draw? SCREEN_W/2 - 100 : (stringwidth(s->name, _fonts.mainmenu)/2 - s->drawdata*1.5)) - m->drawdata[0])/10.0;
	m->drawdata[1] += ((s->draw? (SCREEN_W - 200)*0.85 : stringwidth(s->name, _fonts.mainmenu)) - m->drawdata[1])/10.0;
	m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0;
	
	int i;
	for(i = 0; i < m->ecount; i++) {
		MenuEntry *e = &(m->entries[i]);
		
		e->drawdata += 0.2 * (10*(i == m->cursor) - e->drawdata);
		float a = e->drawdata * 0.1;
		
		if(e->action == NULL)
			glColor4f(0.5, 0.5, 0.5, 0.5);
		else {
			//glColor4f(0.7 + 0.3 * (1-a), 1, 1, 0.7 + 0.3 * a);
			float ia = 1-a;
			glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, 0.7 + 0.3 * a);
		}
		
		if(e->draw)
			e->draw(e, i, m->ecount);
		else if(e->name)
			draw_text(AL_Left, 20 - e->drawdata, 20*i, e->name, _fonts.standard);
	}
	
	glPopMatrix();
	
	fade_out(m->fade);
}
示例#4
0
void FadeAdd(Projectile *p, int t) {
	glBlendFunc(GL_SRC_ALPHA, GL_ONE);
	
	glColor4f(p->clr->r,p->clr->g,p->clr->b, 1.0 - (float)t/p->args[0]);
	glPushMatrix();
	glTranslatef(creal(p->pos), cimag(p->pos), 0);
	glRotatef(180/M_PI*p->angle+90, 0, 0, 1);
	
	draw_texture_p(0,0, p->tex);
	glPopMatrix();
	glColor4f(1,1,1,1);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	
}
示例#5
0
void PartDraw(Projectile *proj, int t) {
	glPushMatrix();
	glTranslatef(creal(proj->pos), cimag(proj->pos), 0);
	glRotatef(proj->angle*180/M_PI+90, 0, 0, 1);

	if(proj->clr)
		glColor4fv((float *)proj->clr);
	
	draw_texture_p(0,0, proj->tex);
	
	glPopMatrix();
	
	if(proj->clr)
		glColor3f(1,1,1);
}
示例#6
0
void Blast(Projectile *p, int t) {
	if(t == 1) {
		p->args[1] = frand()*360 + frand()*I;
		p->args[2] = frand() + frand()*I;
	}
	
	glPushMatrix();
	if(p->pos)
		glTranslatef(creal(p->pos), cimag(p->pos), 0);
	glRotatef(creal(p->args[1]), cimag(p->args[1]), creal(p->args[2]), cimag(p->args[2]));
	if(t != p->args[0])
		glScalef(t/p->args[0], t/p->args[0], 1);
	glColor4f(0.3,0.6,1,1 - t/p->args[0]);
	draw_texture_p(0,0,p->tex);
	glPopMatrix();
	
	glColor4f(1,1,1,1);
}
示例#7
0
void GrowFade(Projectile *p, int t) {
	glPushMatrix();
	glTranslatef(creal(p->pos), cimag(p->pos), 0);
	glRotatef(p->angle*180/M_PI+90, 0, 0, 1);
	
	float s = t/p->args[0]*(1+p->args[1]);
	if(s != 1)
		glScalef(s, s, 1);
	
	if(p->clr)
		glColor4f(p->clr->r,p->clr->g,p->clr->b,1-t/p->args[0]);
	else if(t/p->args[0] != 0)
		glColor4f(1,1,1,1-t/p->args[0]);
	
	draw_texture_p(0,0,p->tex);
	
	glColor4f(1,1,1,1);
	glPopMatrix();
}		
示例#8
0
void _ProjDraw(Projectile *proj, int t) {
	if(proj->clr != NULL && !tconfig.intval[NO_SHADER]) {
		Shader *shader = get_shader("bullet_color");
		glUseProgram(shader->prog);
		
		glUniform4fv(uniloc(shader, "color"), 1, (GLfloat *)proj->clr);
	}
	
	if(proj->clr != NULL && tconfig.intval[NO_SHADER])
		glColor3f(0,0,0);
	
	draw_texture_p(0,0, proj->tex);
	
	if(proj->clr != NULL && tconfig.intval[NO_SHADER])
		glColor3f(1,1,1);
	
	if(!tconfig.intval[NO_SHADER])
		glUseProgram(0);	
}
示例#9
0
文件: texture.c 项目: miton/taisei
void draw_texture(float x, float y, char *name) {
	draw_texture_p(x, y, get_tex(name));
}
示例#10
0
void draw_options_menu(MenuData *menu) {
	draw_options_menu_bg(menu);
	
	draw_text(AL_Right, 140*(1-menu->fade), 30, "Options", _fonts.mainmenu);
	
	glPushMatrix();
	glTranslatef(100, 100, 0);
	
	/*
	glPushMatrix();
	glTranslatef(SCREEN_W/2 - 100, menu->drawdata[2], 0);
	glScalef(SCREEN_W - 200, 20, 1);
	glColor4f(0,0,0,0.5);
	draw_quad();
	glPopMatrix();
	*/
	
	Texture *bg = get_tex("part/smoke");
	glPushMatrix();
	glTranslatef(menu->drawdata[0], menu->drawdata[2], 0);
	glScalef(menu->drawdata[1]/100.0, 0.2, 1);
	glRotatef(menu->frames*2,0,0,1);
	glColor4f(0,0,0,0.5);
	draw_texture_p(0,0,bg);
	glPopMatrix();
	
	OptionBinding *binds = (OptionBinding*)menu->context;
	OptionBinding *bind;
	
	menu->drawdata[0] += ((SCREEN_W/2 - 100) - menu->drawdata[0])/10.0;
	menu->drawdata[1] += ((SCREEN_W - 200) - menu->drawdata[1])/10.0;
	menu->drawdata[2] += (20*menu->cursor - menu->drawdata[2])/10.0;
	
	int i, caption_drawn = 0;
	
	for(i = 0; i < menu->ecount; i++) {
		if(!menu->entries[i].name)
			continue;
		
		menu->entries[i].drawdata += 0.2 * (10*(i == menu->cursor) - menu->entries[i].drawdata);
		float a = menu->entries[i].drawdata * 0.1;
		
		bind = &(binds[i]);
		int hasbind = bind->enabled;
		float alpha = (!hasbind || bind_isactive(bind))? 1 : 0.5;
		
		if(menu->entries[i].action == NULL) {
			glColor4f(0.5, 0.5, 0.5, 0.7 * alpha);
		} else {
			//glColor4f(0.7 + 0.3 * (1-a), 1, 1, (0.7 + 0.3 * a) * alpha);
			float ia = 1-a;
			glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, (0.7 + 0.3 * a) * alpha);
		}
		
		draw_text(AL_Left,
					((hasbind && bind->dependence)? 20 : 0)	// hack hack hack
					+ 20 - menu->entries[i].drawdata, 20*i, menu->entries[i].name, _fonts.standard);
		
		if(hasbind)
		{
			int j, origin = SCREEN_W - 220;
			
			switch(bind->type)
			{
				case BT_IntValue:
					if(bind->valrange_max) {
						char tmp[16];	// who'd use a 16-digit number here anyway?
						snprintf(tmp, 16, "%d", bind_getvalue(bind));
						draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard);
					} else for(j = bind->valcount-1; j+1; --j) {
						if(j != bind->valcount-1)
							origin -= strlen(bind->values[j+1])/2.0 * 20;
						
						if(bind_getvalue(bind) == j) {
							glColor4f(0.9, 0.6, 0.2, alpha);
						} else {
							glColor4f(0.5,0.5,0.5,0.7 * alpha);
						}
							
						draw_text(AL_Right, origin, 20*i, bind->values[j], _fonts.standard);
					}
					break;
				
				case BT_KeyBinding:
					if(bind->blockinput) {
						glColor4f(0.5, 1, 0.5, 1);
						draw_text(AL_Right, origin, 20*i, "Press a key to assign, ESC to cancel", _fonts.standard);
					} else
						draw_text(AL_Right, origin, 20*i, SDL_GetKeyName(tconfig.intval[bind->configentry]), _fonts.standard);
					
					if(!caption_drawn) {
						glColor4f(1,1,1,0.7);
						draw_text(AL_Center, (SCREEN_W - 200)/2, 20*(i-1), "Controls", _fonts.standard);
						caption_drawn = 1;
					}
					break;
				
				case BT_StrValue:
					if(bind->blockinput) {
						glColor4f(0.5, 1, 0.5, 1.0);
						if(strlen(*bind->values))
							draw_text(AL_Right, origin, 20*i, *bind->values, _fonts.standard);
					} else
						draw_text(AL_Right, origin, 20*i, tconfig.strval[bind->configentry], _fonts.standard);
					break;
				
				case BT_Resolution: {
					char tmp[16];
					int w, h;
					
					if(bind->selected == -1) {
						w = video.intended.width;
						h = video.intended.height;
					} else {
						VideoMode *m = &(video.modes[bind->selected]);
						w = m->width;
						h = m->height;
					}
					
					snprintf(tmp, 16, "%dx%d", w, h);
					draw_text(AL_Right, origin, 20*i, tmp, _fonts.standard);
					break;
				}
			}
		}
	}
	
	
	glPopMatrix();
	
	fade_out(menu->fade);
}