Hi guys,its my first time posting here and i found a lot of useful info here so far so i decided to join.
I am using D3D for my school project. I used two mesh files to represent space and a space ship that i can move around.
Problem: I created a count down timer for the fuel level so as the program loads it displays 100L and drops down every 3 seconds. When i run the program, different characters start appearing each second at the end of the line...
ex:
Fuel level: 100L # and then that changes to "...$...%...1...2...3...and so on and then eventually it just stops....
int seconds;
int fuel=100;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
//Fuel Level
if(seconds == 0){
seconds = timeinfo->tm_sec;
}
else{
int tm_now = timeinfo->tm_sec;
if(tm_now - seconds >= 2){
if(fuel > 0){
fuel--;
seconds = timeinfo->tm_sec;
}
}
}
char str1[100];
ostrstream sout(str1,100);
sout<<"Earth time:"<<" "<<asctime (timeinfo)<<endl;
sout<<"Fuel level = "<<fuel<<endl;
// text_xy places 2D text at pixel location (x,y)
text_xy(str1,15,15);
//Taken from Professor
void text_xy(char *str, double x, double y, int size)
// place 2D text at pixel location (x,y)
// str - text string
// x - x pixel location of text
// y - y pixel location of text
// size = font size of the text
{
static TCHAR m_strFont[100];
static DWORD m_dwFontSize = -77; // current font size
// check to see if font size is changed from last call
// this part was added to avoid a memory leak with m_pFont
// and to improve efficiency when font size is not changed
if( size != (int)m_dwFontSize ) {
SAFE_DELETE( m_pFont ); // delete previous font
// Create a new font
lstrcpy( m_strFont, _T("Arial") );
m_dwFontSize = size;
m_pFont = new CD3DFont( m_strFont, m_dwFontSize );
m_pFont->InitDeviceObjects( g_pd3dDevice );
m_pFont->RestoreDeviceObjects();
}
// Draw 2D text
m_pFont->DrawText( (float)x, (float)y, 0xffffffff, _T(str) );
}