www.pudn.com > 3dterrain.zip > Loader.cpp


// Loader.cpp: implementation of the Loader class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "Loader.h" 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
Loader::Loader() 
{ 
	if(!fullscreen) 
	{ 
		RECT		WindowRect;					// miesto pre velkost okna 
		WindowRect.left=(long)0; 
		WindowRect.top=(long)0; 
		GetClientRect(hWnd,&WindowRect);				//zistenie rozmerov uzivatelskej casti okna 
		 
		if (WindowRect.bottom==0) WindowRect.bottom=1; 
		glViewport(0,0,WindowRect.right,WindowRect.bottom);		// Viewport (pohlad) 
		glMatrixMode(GL_PROJECTION);				// projekcia 
		glLoadIdentity();							// Reset pohladu - nacita jednotkovu maticu 
		glOrtho(0,screen_x,0,screen_y,-1,1);		// nastavuje standardne pravouhle premietanie 
		glMatrixMode(GL_MODELVIEW);					// Modelview 
		glLoadIdentity();							// Reset The Modelview Matrix 
	} 
	else  
	{ 
		glViewport(0, 0, screen_x, screen_y);		// Viewport (pohlad) 
		glMatrixMode(GL_PROJECTION);				// projekcia 
		glLoadIdentity();							// Reset pohladu - nacita jednotkovu maticu 
		glOrtho(0,screen_x,0,screen_y,-1,1);		// nastavuje standardne pravouhle premietanie 
		glMatrixMode(GL_MODELVIEW);					// Modelview 
		glLoadIdentity();	 
	} 
 
	glEnable(GL_TEXTURE_2D);		// Povolenie zobrazovanie textúr 
	glShadeModel(GL_SMOOTH);		// nastavuje tienovanie 
 
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //specifikuje hodnoty na cistenie pomocou glClear par.: red, green, blue, alpha (cierny podklad) 
	for(int i=0; i<20; i++) text[i] = NULL; 
	percenta=0; 
	index = -1; 
	Draw(); 
} 
 
Loader::~Loader() 
{ 
	for(int i=0; i<20; i++) if(text[i]!=NULL) delete [] text[i]; 
} 
 
Loader *load;		// instancia 
Font *Loader::font; 
 
void Loader::Draw() 
{ 
	glClear(GL_COLOR_BUFFER_BIT); 
 
	font->Begin(); 
	for(int i=0; i<20; i++)	if(text[i]!=NULL)font->Print_xy_scale(20, 570-i*30, text[i], 1, 1.5f, 1.5f); 
	font->End(); 
	glDisable(GL_DEPTH_TEST); 
	glLoadIdentity(); 
	glDisable(GL_TEXTURE_2D); 
	glBegin(GL_QUADS); 
	glColor3f(1,0,0); 
	glVertex2f(0,0); 
	glColor3f(0,1,0); 
	glVertex2f(percenta*screen_x,0); 
	glColor3f(0,0,1); 
	glVertex2f(percenta*screen_x,30); 
	glColor3f(0,1,0); 
	glVertex2f(0,30); 
	glEnd(); 
	glColor3f(1,1,1); 
	glEnable(GL_TEXTURE_2D); 
	SwapBuffers(hDC); 
} 
 
void Loader::Add(char *t) 
{ 
	index++; 
	if(text[index]!=NULL) delete[] text[index]; 
	text[index] = new char[strlen(t)+1]; 
	strcpy(text[index],t); 
	if(index>=20)index=0; 
	Draw(); 
} 
 
void Loader::Update( char *t, int index_) 
{ 
	if(index_<0 || index_>=20) index_ = 0; 
	if(text[index_]!=NULL) delete[] text[index_]; 
	text[index_] = new char[strlen(t)+1]; 
	strcpy(text[index_],t); 
	Draw(); 
} 
 
void Loader::Add(float per) 
{ 
	percenta+=per; 
	while(percenta>1.05f)percenta-=1.f; 
} 
 
void Loader::Delete() 
{ 
	if(index<0 || index>=20) index=0; 
	if(text[index]!=NULL) delete[] text[index]; 
	text[index] = NULL; 
	index--; 
	if(index<0) index=0; 
}