Using Variables in Display?

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. :stuck_out_tongue: Thanks in advance! :smiley:

1: It’s called snprintf. Or _snprintf if you’re on Windows.

2: This has nothing to do with OpenGL.

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.

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

Question = Refined. Thanks!

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.

Ahh. Now I see what you mean. I figured out the function and results were beautiful. Thank ya!