Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Using Variables in Display?

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    20

    Using Variables in Display?

    Code :
    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.
    Code :
    char defaultframemessage[] = "Frame: %d",framenumber;
    char *framemessage = defaultframemessage;
    Like in printf:
    Code :
    printf("Frame: %d",framenumber);
    Hopefully this is easily possible and there is an obvious solution that I'm not seeing. :P Thanks in advance!

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,713

    Re: Using Variables in Display?

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

    2: This has nothing to do with OpenGL.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    20

    Re: Using Variables in Display?

    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!

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,713

    Re: Using Variables in Display?

    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.

  5. #5
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    20

    Re: Using Variables in Display?

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •