PDA

View Full Version : Using Variables in Display?



Flotonic
05-27-2011, 12:14 PM
char defaultframemessage[] = "Frame: 1";
char *framemessage = defaultframemessage;
I'm needing to use something similar to the printf function here so I can display a value stored in a variable instead of going with preset numbers. I'll express it in code that doesn't work.

char defaultframemessage[] = "Frame: %d",framenumber;
char *framemessage = defaultframemessage;
Like in printf:

printf("Frame: %d",framenumber);
Hopefully this is easily possible and there is an obvious solution that I'm not seeing. :P Thanks in advance! :D

Alfonse Reinheart
05-27-2011, 12:24 PM
1: It's called snprintf. Or _snprintf if you're on Windows.

2: This has nothing to do with OpenGL.

Flotonic
05-27-2011, 01:06 PM
You may not be understanding. I'm not talking about a Command Prompt application. I'm referring to an actual On-Screen Display in an OpenGL application.

http://i364.photobucket.com/albums/oo89/Flotonic/OnScreenDisplayMarioJump.png

The value next to "Frame" will change to be whatever a certain variable has stored.

Question = Refined. Thanks!

Alfonse Reinheart
05-27-2011, 01:21 PM
You have some function which prints strings, yes? You pass it a char*, and it puts that string on the screen.

snprintf is like printf, but it prints directly to a string. Which you can then pass to whatever function prints strings to the screen.

This still isn't an OpenGL question. It's a question of how to generate a string.

Flotonic
05-27-2011, 01:44 PM
Ahh. Now I see what you mean. I figured out the function and results were beautiful. Thank ya!