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: output of integers

  1. #1
    Guest

    output of integers

    Hi,
    I'm currently using VC++6.0 and opengl for simulation purposes. My current problem is more on Visual C++. I need to output integers on the screen using visual C++ facilities. Can I use TextOut? How do I then convert integer to string? If not TextOut, then what else must I use?
    Can I do the same thing using opengl facilities instead of Visual C++?

  2. #2
    Junior Member Newbie
    Join Date
    Sep 2002
    Location
    Beijing,China
    Posts
    3

    Re: output of integers

    I always change integer to string like this in ordinary programming:

    CString str;
    str.Format(" %d",i); // output i
    pDC->TextOut(30,40,str);

    But I'm not sure if it does work in OpenGL programming for I'm a completely newer in it.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Dresden, Sachsen, Germany
    Posts
    205

    Re: output of integers

    i think there is a command like
    wsprintf(...)
    which takes an input and returns an formated string as output, i used to take this function (as far i remember)

  4. #4
    Intern Contributor
    Join Date
    Mar 2002
    Location
    Figueira da Foz, Portugal
    Posts
    84

    Re: output of integers

    wsprintf is for 16 bit wide characters (unicode for example).

    since you're only using regular "" (don't know their name in english ), the function to use is sprintf().

    example:
    Code :
    char str[100];
    int i=13;
    sprintf(str,"%d",i); // str will have "13"
    sprintf will return the number of char's, and you can use that for error-checking

  5. #5
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    247

    Re: output of integers

    To output text in an OpenGL window on Windows, you can use wglUseFontOutlines or wglUseFontBitmaps to create a set of display lists--one for each character--using the current font. You then draw the text using glCallLists. Read the documentation for these functions.

    Converting an integer to a string is the kind of thing you learn in introductory programming classes. You can use sprintf, as someone mentioned, or the stringstream class to do this. If you don't know how to do this, I would suggest that you read a book on C++ programming before attempting to use OpenGL.

    And don't forget, if you just want to see the value of a variable in you program, you can always create a console app and use cout or printf.

Posting Permissions

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