RECT rc2 = {40, 50};
string s = "FPS: ";
s += screenfps;
g_pFont->DrawText(NULL, s.c_str(), -1, &rc2, DT_LEFT | DT_TOP | DT_NOCLIP, 0x66000000);
Problems Printing Text on Screen
So I am trying to print the frame rate on the screen of my game, but when I print it just shows some weird character that looks like [] put together for a second then nothing. I am pretty sure I am handling the string correctly, as it is printing out the FPS: part. Here is my code....any ideas?
thanks
[Edited by - xtheendx on March 7, 2010 7:31:29 PM]
Using:
s += "123";
works for me.
1. What color is your background? Try changing the alpha and the color.
2. Does it work if you don't add "screenfps"?
3. Do you make the call between dev->BeginScene and EndScene?
4. Have you tried checking the return value from DrawText to see if it fails?
s += "123";
works for me.
1. What color is your background? Try changing the alpha and the color.
2. Does it work if you don't add "screenfps"?
3. Do you make the call between dev->BeginScene and EndScene?
4. Have you tried checking the return value from DrawText to see if it fails?
Is screenfps an integer? AFAIK, std::string doesn't define an operator += for integers, so it's possible that it is bringing that integer down to a char and appending that character, although I would think the compiler would issue a warning if it were doing this. You probably want to be using std::stringstream for formatting your strings.
std::stringstream ss;ss << "FPS: " << screenfps;std::string s = ss.str();
Quote:Original post by Buckeye
Using:
s += "123";
works for me.
1. What color is your background? Try changing the alpha and the color.
2. Does it work if you don't add "screenfps"?
3. Do you make the call between dev->BeginScene and EndScene?
4. Have you tried checking the return value from DrawText to see if it fails?
The background is white and I know that isn't the problem because the string "FPS:" prints out fine in grey. and yeah if i do s+= "123"; it prints out "FPS: 123", so it just wont print out the screenfps for some reason. Yes it is between beginscene and endscene. When I set a breakpoint at DrawText it has the value of screenfps as a square symbol. So it is just like it is doing some crazy format to make it output symbols....
thanks
Quote:Original post by aryx
Is screenfps an integer? AFAIK, std::string doesn't define an operator += for integers, so it's possible that it is bringing that integer down to a char and appending that character, although I would think the compiler would issue a warning if it were doing this. You probably want to be using std::stringstream for formatting your strings.
*** Source Snippet Removed ***
perfect...that was the problem with screenfps being a double, it was get turned to a char. I am using VS 2008 and i did not get warning though. Thank you very much, I will have to remember stringstream, never used it before.
Looks like it's as aryx says - you're trying to add a number instead of a string to a string.
Your fps number is being added to the string as a character, not a string. For instance:
s += 123; // adding a number, not the string of a number.
will print out "FPS: {" because 123 is the ASCII code for open curly bracket.
EDIT: simultaneous posts. Glad you can fix it.
Your fps number is being added to the string as a character, not a string. For instance:
s += 123; // adding a number, not the string of a number.
will print out "FPS: {" because 123 is the ASCII code for open curly bracket.
EDIT: simultaneous posts. Glad you can fix it.
Quote:Original post by Buckeye
Looks like it's as aryx says - you're trying to add a number instead of a string to a string.
Your fps number is being added to the string as a character, not a string. For instance:
s += 123; // adding a number, not the string of a number.
will print out "FPS: {" because 123 is the ASCII code for open curly bracket.
EDIT: simultaneous posts. Glad you can fix it.
thank you both, makes perfect since, I shall add this to my brain for future use ;)
Quote:Original post by Anddos
Whats the best way to calculate the fps btw?
I am doing with like this, above BeginScene()
//get current tickscurrenttime = timeGetTime();if (currenttime > refresh + 14){ refresh = currenttime;//calculate screen frame ratescreencount += 1.0;if (currenttime > screentime + 1000) { screenfps = screencount; screencount = 0.0; screentime = currenttime;}}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement