Results 1 to 5 of 5

Thread: HUD for displaying variables

  1. #1
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    HUD for displaying variables

    I have been working on a 3d game (well its not a game yet just the forming of one). So far I have a decent system setup for window rendering and projection, in other words I have the basics cover in most areas. The problem is that I need a really simple HUD system just for displaying variables just so I can make sure all my functions are running correctly. I would like to do this all in one function if possible. I know that I need to setup so that in this function it switches to glortho instead of glperspective. But what I need help with is a really simple way of printing variables to a given x and y coordinate. Is their anyway easy way of archiving this? Thanks

  2. #2
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: HUD for displaying variables

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    now the window goes from (-1,-1) -> (1,1) (u could make 0,0->1,1 if u prefer)

    this is a better method than using fixed X,Y screen coordinates, as u can resize the window + have everything in the correct place

  3. #3
    Junior Member Newbie
    Join Date
    May 2008
    Location
    Manheim, Pa
    Posts
    23

    Re: HUD for displaying variables

    see I was able to figure that much out myself, what I need help with is the actual drawing of the text. Can I just use sprintf or something?

  4. #4
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Nov 2010
    Posts
    2,466

    Re: HUD for displaying variables

    the easiest/most common way is to do text is
    create a texture with the letters of the alphabet on it

    see this program
    http://www.lmnopc.com/bitmapfontbuilder/

    heres a method to draw the text

    create a texture 16 charatcers width by 8 characters high
    starting at the space(ascii==32) and going to the char at ascii32+8*16

    + then use something like the following code

    for ( int i=0; i<strlen(text); i++ )
    {
    num = text[i] - 32;
    char_placeX = num & 15;
    char_placeY = (num >> 4);

    s = char_placeX * 0.0625;
    t = char_placeY * 0.1250;
    VEC3 vec[4];
    vec[0] = VEC3( x, y, 0 );
    vec[1] = VEC3( x+size, y, 0 );
    vec[2] = VEC3( x+size, y+size,0 );
    vec[3] = VEC3( x, y+size, 0 );
    TEXCOORD tc[4];
    tc[0] = TEXCOORD(s+0.0000, t+0.125);
    tc[1] = TEXCOORD(s+0.0625, t+0.125);
    tc[2] = TEXCOORD(s+0.0625, t+0.0);
    tc[3] = TEXCOORD(s+0.0000, t+0.0);

    draw_immediate_quad_v_t_c( vec, tc, text_color );

    x += size;
    }

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: HUD for displaying variables

    Or look at QuesoGLC

Similar Threads

  1. Variables
    By Sidney in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-17-2015, 11:41 AM
  2. too much out variables?
    By Dark_Raven in forum OpenGL: GLSL
    Replies: 9
    Last Post: 12-10-2011, 05:25 PM
  3. Calllists and variables?
    By Andy Gilbert in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-13-2010, 02:04 AM
  4. Displaying variables as text on screen
    By brispace in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-15-2005, 03:03 PM
  5. Using variables...
    By Slashdot'd in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-09-2004, 11:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean