예제 #1
0
void TEXT_DRAW::SetText(
	DRAWABLE & draw,
	const FONT & font, const std::string & text,
	float x, float y, float scalex, float scaley,
	float r, float g, float b,
	VERTEXARRAY & output_array)
{
	RenderText(font, text, x, y, scalex, scaley, output_array);
	draw.SetDiffuseMap(font.GetFontTexture());
	draw.SetVertArray(&output_array);
	draw.SetCull(false, false);
	draw.SetColor(r, g, b, 1.0);
}
예제 #2
0
void ScenePatch(){
	bool quit = false;
	SDL_Event event;

	Sprite *bgi = new Sprite("resource\\bgi_patcher.jpg",1,1);
	Sprite *title = new Sprite("resource\\title.png",1,1);

	FONT gulim;

	float progress_total = 50;
	float progress_current = 30;

	gulim.InitFont("c:\\windows\\fonts\\gulim.ttc",12);
	gulim.SetColor(255,255,255);
	gulim.SetStyle(TTF_STYLE_BOLD);

	while(!quit){
		while(SDL_PollEvent(&event)){
			switch(event.type){
			case SDL_QUIT:
				break;
			}
		}
		{
			SDL_RenderClear(renderer);

			bgi->Draw(0,0,480,272);
			title->Draw(20,20,440,170);


			SDL_Rect rtProgressTotalFrame = {20,200,440,25};
			SDL_Rect rtProgressCurrentFrame = {20,235,440,25};
			SDL_Rect rtProgressTotal = {25,205,progress_total * 4.4,15};
			SDL_Rect rtProgressCurrent = {25,240,progress_current * 4.4,15};

			SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_NONE);
			SDL_SetRenderDrawColor(renderer,64,64,64,255);
			SDL_RenderFillRect(renderer,&rtProgressTotalFrame);
			SDL_RenderFillRect(renderer,&rtProgressCurrentFrame);

			SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
			SDL_SetRenderDrawColor(renderer,64,255,64,196);
			SDL_RenderFillRect(renderer,&rtProgressTotal);
			SDL_RenderFillRect(renderer,&rtProgressCurrent);

			gulim.Draw(renderer,"전체 진행률",25,190);
			gulim.Draw(renderer,"현재 진행률",25,225);

			gulim.Draw(renderer,"Tank Online Patcher",343,258);

			SDL_RenderPresent(renderer);
		}

		SDL_Delay(1);
	}

	delete bgi;
}
예제 #3
0
float TEXT_DRAW::RenderCharacter(
	const FONT & font, char c,
	float x, float y, float scalex, float scaley,
	VERTEXARRAY & output_array)
{
	const FONT::CHARINFO * ci = 0;
	if (!font.GetCharInfo(c, ci)) return 0;

	float invsize = font.GetInvSize();
	float x1 = x + ci->xoffset * invsize * scalex;
	float x2 = x1 + ci->width * invsize * scalex;
	float y1 = y - ci->yoffset * invsize * scaley;
	float y2 = y1 + ci->height * invsize * scaley;

	float u1 = ci->x;
	float u2 = u1 + ci->width;
	float v1 = ci->y;
	float v2 = v1 + ci->height;

	float v[] = {x1, y1, 0, x2, y1, 0, x2, y2, 0, x1, y2, 0};
	float t[] = {u1, v1, u2, v1, u2, v2, u1, v2};
	unsigned f[] = {0, 1, 2, 0, 2, 3};

	if (output_array.GetTexCoordSets() == 0)
	{
		output_array.SetFaces(f, 6);
		output_array.SetVertices(v, 12);
		output_array.SetTexCoordSets(1);
		output_array.SetTexCoords(0, t, 8);
	}
	else
	{
		float * n = 0;
		output_array.Add(n, 0, v, 12, f, 6, t, 8);
	}

	return ci->xadvance * invsize * scalex;
}
예제 #4
0
// 数字文字列のCGを作成
int scg_create_textnum(int wNumCG, int wSize, int wR, int wG, int wB, int wFigs, int wZeroPadding, int wValue) {
	cginfo_t *i;
	agsurface_t *glyph;
	FONT *font;
	char s[256], ss[256];
	
	spcg_assert_no(wNumCG);
	
	if (wZeroPadding) {
		char *sss = "%%0%dd";
		sprintf(ss, sss, wFigs);
	} else {
		char *sss = "%%%dd";
		sprintf(ss, sss, wFigs);
	}
	sprintf(s, ss, wValue);
	
	font = nact->ags.font;
	font->sel_font(FONT_GOTHIC, wSize);
	glyph = font->get_glyph(s);
	
	i = g_new(cginfo_t, 1);
	i->type = CG_SET;
	i->no = wNumCG;
	i->refcnt = 0;
	i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
	gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
	gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
	
	// もし前に作成したものがあり、未開放の場合は開放
	scg_free(wNumCG);
	
	sact.cg[wNumCG] = i;
	
	return OK;
}
예제 #5
0
// 指定の文字列のCGを作成
int scg_create_text(int wNumCG, int wSize, int wR, int wG, int wB, int wText) {
	cginfo_t *i;
	agsurface_t *glyph;
	FONT *font;
	
	if (0) {
		char *b = sjis2lang(v_str(wText-1));
		WARNING("str = '%s'\n", b);
		free(b);
	}
	
	spcg_assert_no(wNumCG);
	
	// 勝手に出ていいのかな?
	if (v_strlen(wText -1) == 0) return OK;
	
	font = nact->ags.font;
	font->sel_font(FONT_GOTHIC, wSize);
	
	glyph = font->get_glyph(v_str(wText -1));
	i = g_new(cginfo_t, 1);
	i->type = CG_SET;
	i->no = wNumCG;
	i->refcnt = 0;
	
	i->sf = sf_create_surface(glyph->width, wSize, nact->ags.dib->depth);
	gr_fill(i->sf, 0, 0, glyph->width, wSize, wR, wG, wB);
	gr_draw_amap(i->sf, 0, 0, glyph->pixel, glyph->width, wSize, glyph->bytes_per_line);
	
	// もし前に作成したものがあり、未開放の場合は開放
	scg_free(wNumCG);
	
	sact.cg[wNumCG] = i;
	
	return OK;
}
예제 #6
0
파일: main.cpp 프로젝트: VDrift/trackeditor
void LoadingScreen(string loadtext)
{
	if (verbose_output)
    	cout << loadtext << endl;

	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glPushMatrix();
	
	utility.Tex2D(3, false);
	utility.Tex2D(2, false);
	utility.Tex2D(1, false);
	utility.Tex2D(0, true);
	
	glSetup();
	
	glEnable(GL_TEXTURE_2D);
	
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer

    Frames++;

	font.Print(0,0,loadtext.c_str(),1,6,1,1,1);
	
	/* Draw it to the screen */
    SDL_GL_SwapBuffers( );

	GLint t = SDL_GetTicks();
	//if (t - T0 >= 50) 
	{
		GLfloat seconds = (t - T0) / 1000.0;
		fps = 1 / seconds;
		//printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
		T0 = t;
		//Frames = 0;
	}
	
	glPopMatrix();
	glPopAttrib();
}
예제 #7
0
void HUD::Update(
	FONT & lcdfont, FONT & sansfont, FONT & sansfont_noshader, float displaywidth, float displayheight,
	float curlap, float lastlap, float bestlap, float stagingtimeleft,
	int curlapnum, int numlaps, int curplace, int numcars,
	float rpm, float redrpm, float maxrpm,
	float speed, float maxspeed, bool mph, float clutch, int newgear,
	const std::string & debug_string1, const std::string & debug_string2,
	const std::string & debug_string3, const std::string & debug_string4,
	bool absenabled, bool absactive, bool tcsenabled, bool tcsactive,
	bool outofgas, bool nosactive, float nosamount,
	bool drifting, float driftscore, float thisdriftscore)
{
	if (!lastvisible)
		return;

	float screenhwratio = displayheight/displaywidth;

	if (debug_hud_info)
	{
		debugtext1.Revise(sansfont, debug_string1);
		debugtext2.Revise(sansfont, debug_string2);
		debugtext3.Revise(sansfont, debug_string3);
		debugtext4.Revise(sansfont, debug_string4);
	}
#ifdef GAUGES
    FONT & gaugefont = sansfont_noshader;

	if (fabs(this->maxrpm - maxrpm) > 1)
	{
		this->maxrpm = maxrpm;
		rpmgauge.Revise(hudroot, gaugefont, 0, maxrpm * 0.001, 1);
	}
	if (fabs(this->maxspeed - maxspeed) > 1 || this->mph != mph)
	{
		this->maxspeed = maxspeed;
		this->mph = mph;
		if (mph)
		{
			speedlabel.Revise(gaugefont, "mph");
			speedscale = 2.23693629;
		}
		else
		{
			speedlabel.Revise(gaugefont, "kph");
			speedscale = 3.6;
		}
		speedgauge.Revise(hudroot, gaugefont, 0, maxspeed * speedscale, 10);
	}
	rpmgauge.Update(hudroot, rpm * 0.001);
	speedgauge.Update(hudroot, fabs(speed) * speedscale);

	// gear
	std::stringstream gearstr;
	if (newgear == -1)
		gearstr << "R";
	else if (newgear == 0)
		gearstr << "N";
	else
		gearstr << newgear;
	geartext.Revise(gaugefont, gearstr.str());

	float geartext_alpha = clutch * 0.5 + 0.5;
	if (newgear == 0) geartext_alpha = 1;
	DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw);
	geartextdrawref.SetColor(1, 1, 1, geartext_alpha);

	// speed
	std::stringstream sstr;
	sstr << std::abs(int(speed * speedscale));
	//float sx = mphtext.GetScale().first;
	//float sy = mphtext.GetScale().second;
	//float w = gaugefont.GetWidth(sstr.str()) * sx;
	//float x = 1 - w;
	//float y = 1 - sy * 0.5;
	mphtext.Revise(gaugefont, sstr.str());//, x, y, fontscalex, fontscaley);
#else
	std::stringstream gearstr;
	if (newgear == -1)
		gearstr << "R";
	else if (newgear == 0)
		gearstr << "N";
	else
		gearstr << newgear;
	geartext.Revise(lcdfont, gearstr.str());

	float geartext_alpha = (newgear == 0) ? 1 : clutch * 0.5 + 0.5;
	DRAWABLE & geartextdrawref = hudroot.GetDrawlist().text.get(geartextdraw);
	geartextdrawref.SetColor(1, 1, 1, geartext_alpha);

	float rpmpercent = std::min(1.0f, rpm / maxrpm);
	float rpmredpoint = redrpm / maxrpm;
	float rpmxstart = 60.0 / displaywidth;
	float rpmwidth = 200.0 / displaywidth;
	float rpmredx = rpmwidth * rpmredpoint + rpmxstart;
	float rpmy = 1.0 - 26.0 / displayheight;
	float rpmheight = 20.0 / displayheight;
	float rpmxend = rpmxstart + rpmwidth * rpmredpoint;
	float rpmrealend = rpmxstart + rpmwidth * rpmpercent;
	if (rpmxend > rpmrealend)
		rpmxend = rpmrealend;
	float rpmredxend = rpmrealend;
	if (rpmrealend < rpmredx)
		rpmredxend = rpmredx;
	rpmbarverts.SetToBillboard(rpmxstart, rpmy, rpmxend, rpmy + rpmheight);
	rpmredbarverts.SetToBillboard(rpmredx, rpmy, rpmredxend, rpmy + rpmheight);
	rpmboxverts.SetToBillboard(rpmxstart, rpmy, rpmxstart + rpmwidth, rpmy + rpmheight);

	std::stringstream speedo;
	if (mph)
		speedo << std::abs((int)(2.23693629 * speed)) << " MPH";
	else
		speedo << std::abs((int)(3.6 * speed)) << " KPH";
	float fontscalex = mphtext.GetScale().first;
	float fontscaley = mphtext.GetScale().second;
	float speedotextwidth = lcdfont.GetWidth(speedo.str()) * fontscalex;
	float x = 1.0 - screenhwratio * 0.02 - speedotextwidth;
	float y = 1 - fontscaley * 0.5;
	mphtext.Revise(lcdfont, speedo.str(), x, y, fontscalex, fontscaley);
#endif
	//update ABS alpha value
	if (!absenabled)
	{
		abs.SetAlpha(hudroot, 0.0);
	}
	else
	{
		if (absactive)
			abs.SetAlpha(hudroot, 1.0);
		else
			abs.SetAlpha(hudroot, 0.2);
	}

	//update TCS alpha value
	if (!tcsenabled)
	{
		tcs.SetAlpha(hudroot, 0.0);
	}
	else
	{
		if (tcsactive)
			tcs.SetAlpha(hudroot, 1.0);
		else
			tcs.SetAlpha(hudroot, 0.2);
	}

	//update GAS indicator
	if (outofgas)
	{
		gas.SetAlpha(hudroot, 1.0);
	}
	else
	{
		gas.SetAlpha(hudroot, 0.0);
	}

	//update NOS indicator
	if (nosamount > 0)
	{
		if (nosactive)
			nos.SetAlpha(hudroot, 1.0);
		else
			nos.SetAlpha(hudroot, 0.2);
	}
	else
	{
		nos.SetAlpha(hudroot, 0.0);
	}

	//update timer info
	{
		std::string tempstr;
		GetTimeString(curlap, tempstr);
		laptime.Revise(tempstr);
		GetTimeString(lastlap, tempstr);
		lastlaptime.Revise(tempstr);
		GetTimeString(bestlap, tempstr);
		bestlaptime.Revise(tempstr);
	}

	//update drift score
	if (numlaps == 0) //this is how we determine practice mode, for now
	{
		std::stringstream scorestream;
		scorestream << "Score " << (int)driftscore;
		if (drifting)
		{
			scorestream << " + " << (int)thisdriftscore;
			driftscoreindicator.SetColor(hudroot, 1,0,0);
		}
		else
		{
			driftscoreindicator.SetColor(hudroot, 1,1,1);
		}
		driftscoreindicator.Revise(scorestream.str());
	}
	else
	{
		driftscoreindicator.SetDrawEnable(hudroot, false);
	}


	if (numlaps > 0)
	{
		//update lap
		std::stringstream lapstream;
		//std::cout << curlapnum << std::endl;
		lapstream << "Lap " << std::max(1, std::min(curlapnum, numlaps)) << "/" << numlaps;
		lapindicator.Revise(lapstream.str());

		//update place
		std::stringstream stream;
		stream << "Place " << curplace << "/" << numcars;
		placeindicator.Revise(stream.str());

		//update race prompt
		std::stringstream t;
		if (stagingtimeleft > 0.5)
		{
			t << ((int)stagingtimeleft)+1;
			raceprompt.SetColor(hudroot, 1,0,0);
			racecomplete = false;
		}
		else if (stagingtimeleft > 0.0)
		{
			t << "Ready";
			raceprompt.SetColor(hudroot, 1,1,0);
		}
		else if (stagingtimeleft < 0.0f && stagingtimeleft > -1.0f) //stagingtimeleft needs to go negative to get the GO message
		{
			t << "GO";
			raceprompt.SetColor(hudroot, 0,1,0);
		}
		else if (curlapnum > numlaps && !racecomplete)
		{
			if (curplace == 1)
			{
				t << "You won!";
				raceprompt.SetColor(hudroot, 0,1,0);
			}
			else
			{
				t << "You lost";
				raceprompt.SetColor(hudroot, 1,0,0);
			}
			raceprompt.Revise(t.str());
			float width = raceprompt.GetWidth();
			raceprompt.SetPosition(0.5-width*0.5,0.5);
			racecomplete = true;
		}

		if (!racecomplete)
		{
			raceprompt.Revise(t.str());
			float width = raceprompt.GetWidth();
			raceprompt.SetPosition(0.5-width*0.5,0.5);
		}
	}
	else
	{
		lapindicator.SetDrawEnable(hudroot, false);
		placeindicator.SetDrawEnable(hudroot, false);
		raceprompt.SetDrawEnable(hudroot, false);
	}
}
예제 #8
0
void SceneLogin(){
	SDL_Event event;
		
	Sprite *bgi = new Sprite("resource\\bgi_login.jpg",1,1);
	Sprite *profile = NULL;

	FONT gulim;
	
	Timer t_login;
	Timer t_result;
	Timer t_cursor;

	int login_animation = 0;
	int result_animation = 0;

	char id[32] = "\0";
	char pw[32] = "\0";
	char *input;
	int id_cur = 0,pw_cur = 0;
	int cursor = 0;
	int cursor_animation = 0;

	int logined = 0;

	int nextScene = 0;

	gulim.InitFont("c:\\windows\\fonts\\gulim.ttc",20);
	gulim.SetColor(0,0,0);
	
	t_login.SetInterval(30);
	t_login.start();
	t_cursor.SetInterval(30);
	t_result.SetInterval(30);

	input = id;

	quit = false;
	while(!quit){
		while(SDL_PollEvent(&event)){
			switch(event.type){
			case SDL_QUIT:
				quit = true;
				break;
	
			case SDL_MOUSEBUTTONDOWN:
				{
					SceneLogin_Signup();
				}
				break;
			// 입력 처리
			case SDL_KEYDOWN:
				if(cursor < 2){
					if(event.key.keysym.sym == SDLK_RETURN){
						cursor ++;
						input = pw;
					}
					else if(event.key.keysym.sym == SDLK_BACKSPACE
							&&
							strlen(input) > 0){
						int len = strlen(input);
						input[len-1] = '\0';
					}
					else{
						if((event.key.keysym.sym >= 'a' && event.key.keysym.sym <= 'z')
							||
							(event.key.keysym.sym >= 'A' && event.key.keysym.sym <= 'Z')
							||
							(event.key.keysym.sym >= '0' && event.key.keysym.sym <= '9')){
							int len = strlen(input);
							input[len] = event.key.keysym.sym;
							input[len+1] = '\0';
						}
					}
				}
				else{
					if(event.key.keysym.sym == SDLK_SPACE){
						quit = true;
						nextScene = 1;
					}
				}
				break;

			case EVENT_LOGIN_OK:
				{
					printf("login ok\n");

					t_result.start();

					// 프로필 이미지 수신이 완료될때까지 대기
					printf("1fileRecv %d\n", fileReceived);
					while(fileReceived == false);
					printf("2fileRecv %d\n", fileReceived);
					fileReceived = false;
					// 로그인 상태를 변경 -> 성공
					logined = 1;

					// 프로필 이미지를 로드
					char path[256];
					sprintf(path,fileName);
					profile = new Sprite(path,1,1,1,1,1);

					sprintf(player.id,id);
					sprintf(player.nick,(char*)event.user.data1);

					printf("%s\n", event.user.data1);

					break;
				}
			case EVENT_LOGIN_DENY:
				printf("login denied\n");
				t_result.start();
				logined = -1;
				break;
			case EVENT_LOGIN_SESSION_EXIST:
				printf("already logged in\n");
				t_result.start();
				logined = -2;
				break;
			case EVENT_LOGOUT_OK:
				printf("logout ok\n");
				break;
			case EVENT_LOGOUT_ERR:
				printf("logout err\n");
				break;
			case EVENT_SIGNUP_OK:
				printf("signup ok\n");
				break;
			case EVENT_SIGNUP_ERR_ID:
				printf("signup err\n");
				break;
			case EVENT_SIGNUP_ERR_UNKNOWN:
				printf("signup err\n");
				break;
			}
		}
		if(t_login.done()){
			if(cursor < 2){
				if(login_animation <= 70)
					login_animation += 2;
			}
			else{
				if(login_animation != 0)
					login_animation -= 2;
				else{
					SceneLogin_DoLogin(id,pw);
					t_login.stop();
				}
			}
			gulim.SetColor(
					255-login_animation*3 - 40,
					255-login_animation*3 - 40,
					255-login_animation*3 - 40);


		}
		if(t_result.done()){
			if(result_animation != 200)
				result_animation += 5;
		}
		if(t_cursor.done()){

		}
		{
			bgi->Draw(0,0,480,272);

			if(logined == 0){
				SDL_Rect rt = {250,170,200,login_animation};
				SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
				SDL_SetRenderDrawColor(renderer,32,64,255,128);
				SDL_RenderFillRect(renderer,&rt);

				SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_NONE);

				gulim.SetStyle(TTF_STYLE_BOLD);
				gulim.Draw(renderer,"ID : ",260,180);
				gulim.Draw(renderer,"PW: ",260,210);

				gulim.SetStyle(TTF_STYLE_NORMAL);
				gulim.Draw(renderer,id,310,180);
				for(int i=0;i<strlen(pw);i++){
					gulim.Draw(renderer,"*",310 + i*10,210);
				}
			}
			else{
				SDL_Rect rt = {150,30,200,result_animation};
				SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
				SDL_SetRenderDrawColor(renderer,32,64,255,128);
				SDL_RenderFillRect(renderer,&rt);

				SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_NONE);

				if(profile != NULL)
					profile->Draw(185,50,130,100);

				gulim.SetStyle(TTF_STYLE_BOLD);
				if(logined == 1){
					gulim.Draw(renderer,player.nick,235,150);
					gulim.Draw(renderer,"입장",230,200);
				}
				else if(logined == -1){
					gulim.Draw(renderer,"로그인실패",195,130);
					gulim.Draw(renderer,"확인",230,200);
				}
				else {
					gulim.Draw(renderer,"이미 접속중",195,130);
					gulim.Draw(renderer,"확인",230,200);
				}
				
			}

			SDL_RenderPresent(renderer);
		}
		

		SDL_Delay(1);
	}
	
	delete bgi;
	if(profile != NULL)
		delete profile;

	if(nextScene == 1)
		SceneGame();
}
예제 #9
0
void MESSAGEQ::Draw(float timefactor, float fps, FONT & font)
{
	int i;

	
	//***update queue
	
	for (i = 0; i < MAX_Q_DEPTH; i++)
	{
		//subtract frame length
		if (valid[i])
			qlen[i] -= timefactor/fps;
		
		//remove expired messages
		if (qlen[i] < 0)
			valid[i] = false;
	}
	
	
	//***sort the queue
	
	int sortnum = 0;
	string sortq[MAX_Q_DEPTH];
	float sortlen[MAX_Q_DEPTH];
	
	bool tempvalid[MAX_Q_DEPTH];
	
	//populate temp vars
	for (i = 0; i < MAX_Q_DEPTH; i++)
	{
		tempvalid[i] = valid[i];
	}
	
	//do the sorting with my kewl VENZALGORITHM
	if (buildup)
	{
		int m;
		for (i = 0; i < MAX_Q_DEPTH; i++)
		{
			float maxval = 0.0f;
			int maxindex = -1;
			
			for (m = 0; m < MAX_Q_DEPTH; m++)
			{
				if (tempvalid[m] && qlen[m] > maxval)
				{
					maxval = qlen[m];
					//tempvalid[m] = false;
					maxindex = m;
				}
			}
			
			if (maxindex < 0)
				break;
			
			sortlen[sortnum] = qlen[maxindex];
			
			if (printtime)
			{
				char tempchar[1024];
				sprintf(tempchar, "%.1f) %s", sortlen[sortnum], q[maxindex].c_str());
				sortq[sortnum] = tempchar;
			}
			else
			{
				sortq[sortnum] = q[maxindex];
			}
			tempvalid[maxindex] = false;
			sortnum++;
		}
	}
	else
	{
		int m;
		for (i = 0; i < MAX_Q_DEPTH; i++)
		{
			float minval = 1000.0f;
			int minindex = -1;
			
			for (m = 0; m < MAX_Q_DEPTH; m++)
			{
				if (tempvalid[m] && qlen[m] < minval)
				{
					minval = qlen[m];
					//tempvalid[m] = false;
					minindex = m;
				}
			}
			
			if (minindex < 0)
				break;
			
			sortlen[sortnum] = qlen[minindex];
			
			if (printtime)
			{
				char tempchar[1024];
				sprintf(tempchar, "%.1f) %s", sortlen[sortnum], q[minindex].c_str());
				sortq[sortnum] = tempchar;
			}
			else
			{
				sortq[sortnum] = q[minindex];
			}
			tempvalid[minindex] = false;
			sortnum++;
		}
	}
	
	
	
	
	
	//***print sorted queue
	
	string strout;
	string finalstr;
	strout = "";
	
	for (i = 0; i < sortnum; i++)
	{
		finalstr = strout;
		
		float white;
		float redtime = 8.0;
		if (sortlen[i] > ((redtime-1.0)*qpersist)/redtime)
			white = 1.0-(sortlen[i]-((redtime-1.0)*qpersist/redtime))/(qpersist/redtime);
		else
			white = 1.0;
		
		float trans;
		if (sortlen[i] < qpersist/4.0)
			trans = sortlen[i]/(qpersist/4.0);
		else
			trans = 1.0;
		
		finalstr.append(sortq[i]);
		font.Print(posx,posy,finalstr.c_str(),fset,size,1,white,white,trans);
		strout.append("\n");
	}
}
예제 #10
0
파일: main.cpp 프로젝트: VDrift/trackeditor
/* general OpenGL initialization function */
int initGL()
{
	//warning:  this must be done BEFORE anything important
	//or else it will override it
	font.Load();
	
    /* Enable Texture Mapping ( NEW ) */
    glEnable( GL_TEXTURE_2D );

    /* Enable smooth shading */
    glShadeModel( GL_SMOOTH );

    /* Set the background black */
    //glClearColor( 0.46f, 0.54f, 0.64f, 0.0f );
	glClearColor(0,0,0,0);

    /* Depth buffer setup */
    glClearDepth( 1.0f );

    /* Enables Depth Testing */
    glEnable( GL_DEPTH_TEST );

    /* The Type Of Depth Test To Do */
    glDepthFunc( GL_LEQUAL );

    /* Really Nice Perspective Calculations */
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );

	/* Position The Light */
    glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );
	
    /* Setup The Diffuse Light */
    glLightfv( GL_LIGHT1, GL_DIFFUSE, LightDiffuse );
	glLightfv( GL_LIGHT1, GL_SPECULAR, LightSpecular );
	
	/* Setup The Ambient Light */
    glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient );

    /* Enable Light One */
    glEnable( GL_LIGHT1 );
	
	/* Enable Lighting */
	glEnable( GL_LIGHTING );
	
	//our perspective matrix
	glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );
	gluPerspective( 45.0f, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, 10000.0f );
	glMatrixMode( GL_MODELVIEW );
	
	
	
	// Enable front face culling, since that's what Quake3 does
    //glCullFace(GL_FRONT);
    //glEnable(GL_CULL_FACE);

	if (!InitGameData())
		return (FALSE);

    return( TRUE );
}
예제 #11
0
파일: main.cpp 프로젝트: VDrift/trackeditor
void ChangeDisplay(int w, int h, int bpp, bool fullscreen, bool reloadtextures)
{
	SCREEN_WIDTH = w;
	SCREEN_HEIGHT = h;
	SCREEN_BPP = bpp;
	
	/* the flags to pass to SDL_SetVideoMode */
    int videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */
    videoFlags |= SDL_HWPALETTE;       /* Store the palette in hardware */
    videoFlags |= SDL_RESIZABLE;       /* Enable window resizing */

    /* This checks to see if surfaces can be stored in memory */
    /*if ( videoInfo->hw_available )
		videoFlags |= SDL_HWSURFACE;
    else
		videoFlags |= SDL_SWSURFACE;

    if ( videoInfo->blit_hw )
	videoFlags |= SDL_HWACCEL;*/

	if (fullscreen)
	{
	  videoFlags |= SDL_HWSURFACE|SDL_ANYFORMAT|SDL_FULLSCREEN;  
	}	
	else
	{
	  videoFlags |= SDL_SWSURFACE|SDL_ANYFORMAT;
	}
	
    /* get a SDL surface */
	if (surface != NULL)
	{
		SDL_FreeSurface(surface);
		surface = NULL;
	}
    surface = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,
				videoFlags );
	
	resizeWindow( SCREEN_WIDTH, SCREEN_HEIGHT );
	//if (fullscreen)
	
/*
	ofstream vconf;
	vconf.open((settings.GetSettingsDir() + "/videoconfig").c_str());
	vconf << w << " ";
	vconf << h << " ";
	vconf << bpp << " ";
	vconf << fullscreen << " ";
	vconf.close();
*/
	settings.SetDisplayX(w);
	settings.SetDisplayY(h);
	settings.SetDisplayDepth(bpp);
	settings.SetFullscreenEnabled(fullscreen);

	if (reloadtextures)
	{
        font.Load();
	}
}
예제 #12
0
파일: main.cpp 프로젝트: VDrift/trackeditor
/* Here goes our drawing code */
int drawGLScene()
{
	#ifdef PERFORMANCE_PROFILE
	suseconds_t t1, t2;
	t1 = GetMicroSeconds();
	t1 = GetMicroSeconds();
	#endif
	
	//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "RenderReflectedScene() ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	#endif
	
	glMatrixMode( GL_PROJECTION );
	glLoadIdentity( );
	gluPerspective( 45.0f, (float)SCREEN_WIDTH/SCREEN_HEIGHT, 0.1f, settings.GetViewDistance() );
	glMatrixMode( GL_MODELVIEW );
	
	glSetup();
	
	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); 
	//glClearColor( 255.0f, 0.0f, 0.0f, 0.0f ); 
	
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "glSetup() ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	#endif
	
	utility.Tex2D(3, false);
	utility.Tex2D(2, false);
	utility.Tex2D(1, false);
	utility.Tex2D(0, true);
	
	glStencilMask(~0);
	glClearStencil(0);
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);		// Clear Screen And Depth Buffer
	
	glDisable(GL_STENCIL_TEST);

	
	GLdouble temp_matrix[16];
	int i;
	
	

	cam.PutTransformInto(temp_matrix);
	glLoadMatrixd(temp_matrix);
	
	//reset sun position so it's in the correct frame
	float lp[4];
	lp[0] = LightPosition[0];
	lp[1] = LightPosition[1];
	lp[2] = LightPosition[2];
	lp[3] = 0;
	
	//lighting hardcoded to reasonable position
	lp[0] = 3;
	lp[1] = 3;
	lp[2] = 3;
	lp[3] = 0;
	glLightfv( GL_LIGHT1, GL_POSITION, lp );
	
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "Matrix setup and light setup ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	#endif
	
	// model the highlighted vertex belongs to
	OBJECTMODEL * highlighted_model = NULL;
	//if (state.GetGameState() != STATE_INITIALMENU)
	{
		
//		bool normal = true;
		
		glClear (GL_DEPTH_BUFFER_BIT);
		
		#ifdef PERFORMANCE_PROFILE
		t2 = GetMicroSeconds();
		cout << "DrawSky() ticks: " << t2-t1 << endl;
		t1 = GetMicroSeconds();
		#endif
		
		glTranslatef(cam.GetPosition().x,cam.GetPosition().y,cam.GetPosition().z);
	
		/*GLdouble equation[4];
		VERTEX earthnormal = temp - cam.position;
		earthnormal.y += EARTH_RADIUS;
		earthnormal = earthnormal.normalize();
		equation[0] = earthnormal.x;
		equation[1] = -earthnormal.y;
		equation[2] = earthnormal.z;
		equation[3] = (waterheight);
		glClipPlane(GL_CLIP_PLANE1, equation);
		if (underwater)
			glEnable(GL_CLIP_PLANE1);
		else
			glDisable(GL_CLIP_PLANE1);
		*/
		
				
		#ifdef PERFORMANCE_PROFILE
		t2 = GetMicroSeconds();
		cout << "terrain.SetFrustum() ticks: " << t2-t1 << endl;
		t1 = GetMicroSeconds();
		#endif
		
		//glPolygonOffset(1.0,1.0);
		//glPolygonOffset(0.0,10.0);
		//glEnable(GL_POLYGON_OFFSET_FILL);
	
		/*if (normal)
		{
			//GLfloat LightAmbient2[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
			//glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient2 );
			glDisable(GL_STENCIL_TEST);
			
			#ifdef PERFORMANCE_PROFILE
			t2 = GetMicroSeconds();
			cout << "terrain.Draw() ticks: " << t2-t1 << endl;
			t1 = GetMicroSeconds();
			#endif
			
			utility.SelectTU(3);
			glDisable(GL_TEXTURE_2D);
			utility.SelectTU(0);
			glEnable(GL_TEXTURE_2D);

			#ifdef PERFORMANCE_PROFILE
			t2 = GetMicroSeconds();
			cout << "trees.Draw() ticks: " << t2-t1 << endl;
			t1 = GetMicroSeconds();
			#endif
			objects.Draw();
			#ifdef PERFORMANCE_PROFILE
			t2 = GetMicroSeconds();
			cout << "objects.Draw() ticks: " << t2-t1 << endl;
			t1 = GetMicroSeconds();
			#endif
			
			//glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient );
		}
		
		glDisable(GL_POLYGON_OFFSET_FILL);*/
		
		//glClear (GL_DEPTH_BUFFER_BIT);
		
		//glDisable(GL_LIGHTING);
		objects.Draw();
		
		#ifdef PERFORMANCE_PROFILE
		t2 = GetMicroSeconds();
		cout << "normal draw done" << t2-t1 << endl;
		t1 = GetMicroSeconds();
		#endif
	
		/*
		//draw trees
		foliage.Draw(terrain, cam);
		
		#ifdef PERFORMANCE_PROFILE
		t2 = GetMicroSeconds();
		cout << "foliage.Draw() ticks: " << t2-t1 << endl;
		t1 = GetMicroSeconds();
		#endif
	
		//glDisable(GL_CLIP_PLANE1);
		ships.Draw(false);
	
		terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time);
		//terrain.Draw(cam, 1.0f, false, false, true, false, timefactor, fps, day_time);
		
		//rain is drawn over everything else
		if (!underwater)
			backdrop.DrawRain(day_time);
	
		
		#ifdef PERFORMANCE_PROFILE
		t2 = GetMicroSeconds();
		cout << "DrawRain() ticks: " << t2-t1 << endl;
		t1 = GetMicroSeconds();
		#endif
		
		
		glDisable(GL_CLIP_PLANE1);
	*/	
	
		
		//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		
		/*if (0)
		{	
			//experimental bezier stuff
			BEZIER patch;
			VERTEX fl, fr, bl, br;
			//fl.Set(20,40,0);
			fl.Set(5,10,0);
			fr = fl;
			bl = fl;
			br = fl;
			
			fr.x += 15;
			fr.y += 3;
			
			br.x += 12;
			br.z += 8;
			
			bl.z += 10;
			bl.y -= 2;
			
			patch.SetFromCorners(fl, fr, bl, br);
			
			BEZIER nextpatch;
			VERTEX offset;
			offset.x += -7;
			offset.z += -10;
			fl = fl + offset;
			fr = fr + offset;
			bl = bl + offset;
			br = br + offset;
			
			nextpatch.SetFromCorners(fl, fr, bl, br);
			
			//patch.Attach(nextpatch);
			
			BEZIER thirdpatch;
			offset.zero();
			offset.y += -3;
			offset.z += -10;
			fl = fl + offset;
			fr = fr + offset;
			bl = bl + offset;
			br = br + offset;
			
			thirdpatch.SetFromCorners(fl, fr, bl, br);
			
			//nextpatch.Attach(thirdpatch);
			
			TRACK track;
			ROADSTRIP * teststrip = track.AddNewRoad();
			teststrip->Add(patch);
			teststrip->Add(nextpatch);
			teststrip->Add(thirdpatch);
			
			//teststrip.DeleteLastPatch();
					
			track.VisualizeRoads(true, true);
			
			VERTEX down;
			down.y = -1;
			VERTEX colpoint;
			if (patch.Collide(cam.position.ScaleR(-1.0), down, colpoint))
			{
				//colpoint.DebugPrint();
			}
		}*/
		
		VERTEX camray;
		camray.z = -1;
		camray = cam.dir.ReturnConjugate().RotateVec(camray);
		/*camray.z = 1;
		camray = cam.dir.RotateVec(camray);*/
		VERTEX selvert;
		bool highlightedvert = false;
		if (objects.FindClosestVert(cam.position.ScaleR(-1.0), camray, selvert, highlighted_model))
		{
			/*cam.position.ScaleR(-1.0).DebugPrint();
			selvert.DebugPrint();
			cout << endl;*/
			
			//draw a highlighted vert
			
			highlightedvert = true;
			
			glPushAttrib(GL_ALL_ATTRIB_BITS);
			glDisable(GL_LIGHTING);
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_DEPTH_TEST);
			//glEnable(GL_BLEND);
			//glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
			glPointSize(4.0);
			//glColor4f(1,1,0,0.75);
			glColor4f(1,1,0,1);
			glBegin(GL_POINTS);
			glVertex3fv(selvert.v3());
			glEnd();
			glDisable(GL_BLEND);
			glColor4f(1,1,1,1);
			glPopAttrib();
		}
		
		//left click
		if (highlightedvert && mouse.ButtonDown(1) && !editordata.mousebounce[1])
		{
			int oldnumbezinput = editordata.numbezinput;
			
			//left click on a highlighted vert
			if (vertmode == TWOVERTS)
			{
				if (editordata.numbezinput == 0)
					editordata.numbezinput = 3;
				else if (editordata.numbezinput <= 3)
					editordata.numbezinput = 4;
				else if (editordata.numbezinput <= 4)
					editordata.numbezinput = 7;
				else if (editordata.numbezinput <= 7)
					editordata.numbezinput = 8;
			}
			else
			{
				editordata.numbezinput++;
				if (vertmode == THREEVERTS && (editordata.numbezinput == 2 || editordata.numbezinput == 6))
					editordata.numbezinput++;
			}
			
			if (editordata.numbezinput >= 8)
			{
				//create bezier patch
				BEZIER patch;
				
				if (vertmode == TWOVERTS)
					patch.SetFromCorners(editordata.bezinput[4], selvert, editordata.bezinput[0], editordata.bezinput[3]);
				else
				{
					//copy the front and back selected rows to the patch, then tell it to do the math to find the other points
					// plus center and radius calculations
					
					editordata.bezinput[7] = selvert;
					
					for (int i = 0; i < 4; i++)
						patch.points[3][i] = editordata.bezinput[i];
					for (int i = 0; i < 4; i++)
						patch.points[0][i] = editordata.bezinput[i+4];
					
					/*if (vertmode == THREEVERTS)
					{
						//recalculate the middle two verts
						for (int i = 0; i < 4; i += 3)
						{
							if ((patch.points[i][1] - patch.points[i][2]).len() < 0.0001)
							{
								VERTEX leftslope = patch.points[i][1] - patch.points[i][0];
								VERTEX rightslope = patch.points[i][2] - patch.points[i][3];
								patch.points[i][1] = patch.points[i][0] + leftslope.ScaleR(0.5);
								patch.points[i][2] = patch.points[i][3] + rightslope.ScaleR(0.5);
							}
						}
					}*/
					
					patch.CalculateMiddleRows();
				}
				
				if (activestrip == NULL)
				{
					activestrip = track.AddNewRoad();
					mq1.AddMessage("New road created to hold new patch.");
				}
				
				activestrip->Add(patch);
				
				//editordata.numbezinput = 0;
				editordata.numbezinput = 4;
				
				editordata.bezinput[0] = patch.points[0][0];
				editordata.bezinput[1] = patch.points[0][1];
				editordata.bezinput[2] = patch.points[0][2];
				editordata.bezinput[3] = patch.points[0][3];
			}
			else
			{
				editordata.bezinput[oldnumbezinput] = selvert;
				if (vertmode == THREEVERTS && (oldnumbezinput == 1 || oldnumbezinput == 5))
					editordata.bezinput[oldnumbezinput+1] = selvert;
			}
		}
		
		editordata.mousebounce[1] = mouse.ButtonDown(1);
		
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glDisable(GL_LIGHTING);
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_DEPTH_TEST);
		glPointSize(4.0);
		glColor4f(1,0,0,1);
		glBegin(GL_POINTS);
		for (i = 0; i < editordata.numbezinput; i++)
		{
			if (vertmode != TWOVERTS || i == 0 || i == 3 || i == 4 || i == 7)
			{
				glVertex3fv(editordata.bezinput[i].v3());
			}
		}
		glEnd();
		glColor4f(1,1,1,1);
		glPopAttrib();
		
		track.VisualizeRoads(true, false, activestrip);
		
		for (int l = 0; l < track.NumLapSeqs(); l++)
		{
			BEZIER * lapbez = track.GetLapSeq(l);
			if (lapbez != NULL)
			{
				VERTEX reddish;
				reddish.x = 0.5;
				reddish.y = 0.2;
				reddish.z = 0.2;
				lapbez->Visualize(true, false, reddish);
			}
		}
		
		
		//image in the framebuffer is now complete.
		
		
		/*//add a brightness/contrast adjustment
		glClear (GL_DEPTH_BUFFER_BIT);
		glLoadIdentity();
		glPushAttrib(GL_ALL_ATTRIB_BITS);
		glDisable(GL_TEXTURE_2D);
		glEnable(GL_BLEND);
		glDisable(GL_FOG);
		glDisable(GL_LIGHTING);
		glTranslatef(0,0,-40.0f);
		glBlendFunc(GL_ONE, GL_SRC_ALPHA);
		
		float rd = (float) weathersystem.GetRainDrops();
		
		float rainscale = 0.7f;
		float clearscale = 1.1f;
		float rainbias = 0.035f;
		float clearbias = 0.0f;
		float rainmax = 50.0f;
		
		float rainfactor = (rd/rainmax);
		if (rainfactor > 1.0f)
			rainfactor = 1.0f;
	
		float scale = rainfactor*rainscale+(1.0f-rainfactor)*clearscale;
		float bias = rainfactor*rainbias+(1.0f-rainfactor)*clearbias;
	
	
		glColor4f(bias, bias, bias, scale);
		float x1, y1, x2, y2;
		x1 = -30;
		y1 = -30;
		x2 = 30;
		y2 = 30;
		
		if (scale > 1.0) 
		{
			float remainingScale;
			
			remainingScale = scale;
			glBlendFunc(GL_DST_COLOR, GL_ONE);
			if (remainingScale > 2.0) 
			{
				glColor4f(1, 1, 1, 1);
				while (remainingScale > 2.0) 
				{
					glRectf(x1,y1,x2,y2);
					remainingScale /= 2.0;
				}
			}
			glColor4f(remainingScale - 1,
				remainingScale - 1, remainingScale - 1, 1);
			glRectf(x1,y1,x2,y2);
			glBlendFunc(GL_ONE, GL_ONE);
			if (bias != 0)
			{
				if (bias > 0) 
				{
					glColor4f(bias, bias, bias, 0.0);
				} 
				else 
				{
					glColor4f(-bias, -bias, -bias, 0.0);
					//can't do bias < 0
				}
				glRectf(x1,y1,x2,y2);
			}
		}
		else 
		{
			if (bias > 0) 
			{
				glColor4f(bias, bias, bias, scale);
			}
			else 
			{
				glColor4f(-bias, -bias, -bias, scale);
				//can't do bias < 0
			}
			glBlendFunc(GL_ONE, GL_SRC_ALPHA);
			glRectf(x1,y1,x2,y2);
		}
		
		glPopAttrib();*/
	
		//timer.Draw();
	}
	
	float w, h;
	w = 0.02;
	h = w*(4/3.0);
	utility.Tex2D(0,true);
	utility.Draw2D(0.5-w, 0.5-h, 0.5+w, 0.5+h, editordata.cursortex);
	
	if (fps > 0.0f)
		mq1.Draw(timefactor, fps, font);
	
	
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "Brightness/contrast adjustment ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	#endif

	
	
    Frames++;
	frameno++;
	if (frameno >= 30011)
		frameno -= 30011;
	lfps[lfpspos] = pfps;
	lfpspos++;
	if (lfpspos >= AVERAGEFRAMES)
	{
		lfpspos = lfpspos % AVERAGEFRAMES;
		lfpsfull = true;
	}
	
	float tfps = 0.0f;
	int tnum = 0;
	for (i = 0; i < AVERAGEFRAMES; i++)
	{
		if (!(!lfpsfull && i >= lfpspos))
		{
			tfps += lfps[i];
			tnum++;
		}
	}
	fps = std::min(1000.0f,tfps / (float) tnum);
	
	/*lfps += pfps;
    {
		//const int freq = (int) MIN_FPS;
		const int freq = 60;
		if (Frames >= freq)
		{
			fps = lfps / freq;
			Frames = 0;
			lfps = 0;
		}
	}*/
	
	char tempchar[1024];
	sprintf(tempchar, "Frames per second: %f\n", fps);
	
	//font.Print(0.5,0,tempchar,0,0,1,1,0);
	if (showfps)
		font.Print( 0.75, 0.0, tempchar, 1, 5, 1.0 );
	
	// print camera position
	VERTEX pos = cam.GetPosition();
	sprintf(tempchar, "Position: %0.2f, %0.2f, %0.2f\n", -pos.x, -pos.y, -pos.z);
	font.Print( 0.75, 0.025, tempchar, 1, 5, 1.0 );
	
	//VERTEX ang = cam.dir.GetEulerZYX();
	//sprintf(tempchar, "Angle: %0.2f, %0.2f, %0.2f\n", 180/M_PI*ang.x, -180/M_PI*ang.y, 180/M_PI*ang.z);
	//font.Print( 0.75, 0.05, tempchar, 1, 5, 1.0 );
	
	// print object name the highlighted vertex belongs to
	if (highlighted_model)
	{
		string modelname = highlighted_model->name;
		sprintf(tempchar, "Model: %s\n", modelname.c_str());
		font.Print( 0.75, 0.05, tempchar, 1, 5, 1.0 );
	}
	
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "font.Print() ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	#endif
	
	
	//draw help screen(s)
	if (editordata.helppage > 2)
		editordata.helppage = 0;
	if (editordata.helppage == 1)
	{
		font.Print(0.1, 0.1, "VDrift Track Editor Keys (press H again for more help)\n"
	"Mouse left click\n"
	"Arrow keys\n"
	"Page Up\n"
	"A, F\n"
	"L\n"
	"K\n"
	"N\n"
	"R\n"
	"S\n"
	"I\n"
	"E\n"
	"- (minus)\n"
	"2, 3, 4\n"
	"BACKSPACE\n"
	"ESCAPE\n"
	, 1, 5, 1.0);
		font.Print(0.3, 0.1, "\n"
	"Select highligted vertex\n"
	"Move around\n"
	"Move forward very fast\n"
	"Automatically try to create the next bezier patch on this road (F: 25 at a time)\n"
	"Add the current camera position to the list of car start locations\n"
	"Remove the last start location from the list\n"
	"Create a new road (the new road is created once you add patches to it)\n"
	"Select the road under the cursor\n"
	"Save the track\n"
	"Print the object that owns the selected vertex to the console\n"
	"Mark a road segment as part of a lap sequence\n"
	"Clear all lap sequences\n"
	"Select vertices 2 at a time, 3 at a time, 4 at a time\n"
	"Delete the last bezier patch on this road\n"
	"Quit the editor\n"
	, 1, 5, 1.0);
	}
	if (editordata.helppage == 2)
		font.Print(0.1, 0.1, "VDrift Track Editor Textual Help\n"
	"The editor starts in vertex selection mode.  Vertices are highlighted yellow as the mouse pointer\n"
	"gets close to them.  Press the left mouse button to select the highlighted vertex.  It will turn\n"
	"red.  Select a vertex on the left side of the road, then a vertex on the right side of the road,\n"
	"with left and right determined by the direction you'd like to create the road in.  You can now select\n"
	"the next two vertices (left and then right), and a green box will be created to indicate a bezier\n"
	"patch has been created there.  Notice that the last two vertices you select are still colored red\n"
	"(selected).  You can now select the next two vertices (left and right), and continue to create bezier\n"
	"patches around the track.  Once you have created a bezier patch, you can alternatively press A to\n"
	"have the editor try to automatically select the next two vertices and auto-create the next patch.\n"
	"This works well in straight areas, not so well in curvy areas.  Press BACKSPACE at any time to delete\n"
	"the last patch that was created."
	, 1, 5, 1.0);


	/* Draw it to the screen */
    SDL_GL_SwapBuffers( );

    
		GLint t = SDL_GetTicks();
		//if (t - T0 >= 50) 
		{
			GLfloat seconds = (t - T0) / 1000.0;
			pfps = 1 / seconds;
			//printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
			T0 = t;
			//Frames = 0;
		}
		
	#ifdef PERFORMANCE_PROFILE
	t2 = GetMicroSeconds();
	cout << "SwapBuffers() ticks: " << t2-t1 << endl;
	t1 = GetMicroSeconds();
	cout << endl;
	#endif
		
    return( TRUE );
}
예제 #13
0
파일: hudgauge.cpp 프로젝트: Bengt/vdrift
void HUDGAUGE::Set(
	SCENENODE & parent,
	const FONT & font,
	const std::string & name,
	float hwratio,
	float centerx,
	float centery,
	float radius,
	float startangle,
	float endangle,
	float startvalue,
	float endvalue,
	float valuedelta)
{
	// calculate number of segments (max 9)
	float segments = (endvalue - startvalue) / valuedelta;
	float factor = ceil(segments / 9.0f);
	segments = ceil(segments / factor);
	valuedelta = valuedelta * factor;
	endvalue = startvalue + segments * valuedelta;

	this->centerx = centerx;
	this->centery = centery;
	this->scalex = radius * hwratio;
	this->scaley = radius;
	this->offset = startangle;
	this->scale = (endangle - startangle) / (endvalue - startvalue);

	// reset
	Erase(parent, pointer_draw);
	Erase(parent, dialnum_draw);
	Erase(parent, dial_draw);
	pointer_rotated.Clear();
	pointer.Clear();
	dial_label.Clear();
	dial_marks.Clear();

	// dial marks
	{
		// big marker
		float pb[] = {-0.02, 1, 0, 0.02, 1, 0, 0.02, 0.92, 0, -0.02, 0.92, 0};
		float t[] = {0, 0, 1, 0, 1, 1, 0, 1};
		int f[] = {0, 2, 1, 0, 3, 2};
		VERTEXARRAY bm;
		bm.SetVertices(pb, 12);
		bm.SetTexCoordSets(1);
		bm.SetTexCoords(0, t, 8);
		bm.SetFaces(f, 6);

		// small marker
		float ps[] = {-0.01, 1, 0, 0.01, 1, 0, 0.01, 0.95, 0, -0.01, 0.95, 0};
		VERTEXARRAY sm;
		sm.SetVertices(ps, 12);
		sm.SetTexCoordSets(1);
		sm.SetTexCoords(0, t, 8);
		sm.SetFaces(f, 6);

		float delta = (endangle - startangle) / (3 * segments);
		float angle = startangle;
		for (int i = 0; i <= 3 * segments; ++i)
		{
			VERTEXARRAY temp = (i % 3) ? sm : bm;
			temp.Rotate(angle, 0, 0, -1);
			dial_marks = dial_marks + temp;
			angle = angle + delta;
		}
		dial_marks.Scale(radius * hwratio, radius, 1);
		dial_marks.Translate(centerx, centery, 0.0);

		dial_draw = AddDrawable(parent);
		DRAWABLE & drawref = GetDrawable(parent, dial_draw);
		drawref.SetVertArray(&dial_marks);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(1);
	}

	// dial label
	{
		VERTEXARRAY temp;
		float w = 0.25 * radius * hwratio;
		float h = 0.25 * radius;
		float x = centerx;
		float y = centery - 0.5 * radius;
		float xn = TEXT_DRAW::RenderText(font, name, x, y, w, h, temp);
		temp.Translate((x - xn) * 0.5, 0, 0);
		dial_label = dial_label + temp;

		float angle = startangle;
		float angle_delta = (endangle - startangle) / segments;
		float value = startvalue;
		float value_delta = (endvalue - startvalue) / segments;
		for (int i = 0; i <= segments; ++i)
		{
			std::stringstream sstr;
			std::string text;
			sstr << value;
			sstr >> text;
			x = centerx + 0.75 * sin(angle) * radius * hwratio;
			y = centery + 0.75 * cos(angle) * radius;
			xn = TEXT_DRAW::RenderText(font, text, x, y, w, h, temp);
			temp.Translate((x - xn) * 0.5, 0, 0);
			dial_label = dial_label + temp;
			angle += angle_delta;
			value += value_delta;
		}

		dialnum_draw = AddDrawable(parent);
		DRAWABLE & drawref = GetDrawable(parent, dialnum_draw);
		drawref.SetDiffuseMap(font.GetFontTexture());
		drawref.SetVertArray(&dial_label);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(1);
	}

	// pointer
	{
		float p[] = {-0.015, 0.92, 0, 0.015, 0.92, 0, 0.025, -0.1, 0, -0.025, -0.1, 0};
		float t[] = {0, 0, 1, 0, 1, 1, 0, 1};
		int f[] = {0, 2, 1, 0, 3, 2};
		pointer.SetVertices(p, 12);
		pointer.SetTexCoordSets(1);
		pointer.SetTexCoords(0, t, 8);
		pointer.SetFaces(f, 6);
/*		pointer.Scale(radius, radius, 1);

		pointer_node = parent.AddNode();
		SCENENODE & noderef = parent.GetNode(pointer_node);
		QUATERNION<float> rot(startangle, 0, 0, 1);
		MATHVECTOR<float,3> pos(centerx, centery, 0);
		noderef.GetTransform().SetRotation(rot);
		noderef.GetTransform().SetTranslation(pos);
*/
		pointer_draw = AddDrawable(parent);//noderef);
		DRAWABLE & drawref = GetDrawable(parent, pointer_draw);//noderef, pointer_draw);
		drawref.SetVertArray(&pointer_rotated);//pointer);
		drawref.SetCull(false, false);
		drawref.SetColor(1, 1, 1, 0.5);
		drawref.SetDrawOrder(2);
	}
}
예제 #14
0
float WIDGET_LABEL::GetWidth(const FONT & font, const std::string & text, float scale) const
{
	return font.GetWidth(text) * scale;
}