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 2 of 2

Thread: Haaaaaaaaa tired of this!! glOrtho for console

  1. #1
    Guest

    Haaaaaaaaa tired of this!! glOrtho for console

    Well i would like to do a console (like in quake) and so i use glOrtho but i wan't to have the coordinates like this:

    (x, y)
    0,0 ------x-----1,0
    | |
    | |
    | |
    y |
    | |
    | |
    0,1-------------1,1

    and add text with

    glTexCoord2f( u, v); glVertex2f( x, y);
    glTexCoord2f(u + 1/16, v); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y);
    glTexCoord2f(u + 1/16, v + 1/16); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y-1/MAX_CONSOLE_ROW);
    glTexCoord2f( u, v + 1/16); glVertex2f( x, y-1/MAX_CONSOLE_ROW);

    x := x + 1/MAX_CONSOLE_COLUMN;

    BUT i don't manage to do it.... let's look some code (sorry , it's in delphi):


    >>>>>>>>>>>>>>>
    WM_LBUTTONDOWN:
    begin
    glViewport(0,0,dwWidth,dwHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.,800/600,0.01,100);

    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();


    (*
    // WORK a little
    glOrtho (-1.0, 1.0, // (left, bottom)
    -1.0, 1.0, // (right, top)
    -1.0, 1.0);// (znear, zfar)
    glTranslatef(0.0, 0.0, 1.0);
    *)

    glOrtho(g_fOrthoVars[ORTHO_LEFT], g_fOrthoVars[ORTHO_RIGHT],
    g_fOrthoVars[ORTHO_BOTTOM], g_fOrthoVars[ORTHO_TOP],
    g_fOrthoVars[ORTHO_ZNEAR], g_fOrthoVars[ORTHO_ZFAR]);
    glTranslatef(0.0, 0.0, 1.0);


    (*
    // WORK
    glRotatef(180, 1.0, 0.0, 0.0);
    glTranslatef( 0.0, 0.0, 1.0);
    glTranslatef(-0.55, -0.39, 0.0);
    *)

    //glTranslatef( 0.0, 0.0, -1.0);


    // Axis
    glDisable(GL_TEXTURE_2D);
    glbegin(GL_LINES);
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(1.0, 0.0, 0.0);

    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 1.0, 0.0);

    glColor3f(0.0, 0.0, 1.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(0.0, 0.0, 1.0);
    glEnd();

    Font.Bind();

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_CULL_FACE);
    glColor3f(1.0, 1.0, 1.0);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    x := 0;
    y := 0;

    //strText := 'Hello World! Test : ²&é"''(-è_çà)=^$ù*,;:!~#{[|`\^@]}¨£%µ?./§';
    case nCurrent of
    ORTHO_LEFT : strText := 'ORTHO_LEFT = ';
    ORTHO_RIGHT : strText := 'ORTHO_RIGHT = ';
    ORTHO_BOTTOM : strText := 'ORTHO_BOTTOM = ';
    ORTHO_TOP : strText := 'ORTHO_TOP = ';
    ORTHO_ZNEAR : strText := 'ORTHO_ZNEAR = ';
    ORTHO_ZFAR : strText := 'ORTHO_ZFAR = ';
    end;

    strText := strText + FloatToStrF(g_fOrthoVars[nCurrent], ffFixed, 0, 3);
    n := Length(strText);

    // **********
    glBegin(GL_QUADS);

    for i:=1 to n do
    begin
    c := strText[i];

    nc := Integer(c);

    (*
    0 1
    3 2
    *)
    u := (nc mod 16) / 16;
    v := 1 - ((nc div 16) + 1 )/ 16;

    //glNormal3f(0.0, 0.0, -1.0);

    glTexCoord2f( u, v); glVertex2f( x, y);
    glTexCoord2f(u + 1/16, v); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y);
    glTexCoord2f(u + 1/16, v + 1/16); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y-1/MAX_CONSOLE_ROW);
    glTexCoord2f( u, v + 1/16); glVertex2f( x, y-1/MAX_CONSOLE_ROW);

    x := x + 1/MAX_CONSOLE_COLUMN;
    end;

    glEnd();
    // **********

    SwapBuffers(h_DC);
    end;
    >>>>>>>

    It's not clean i now but i will clean it when it will works...

    Thanks for help, it's kind of urgent.
    TheDD

  2. #2
    Guest

    Re: Haaaaaaaaa tired of this!! glOrtho for console

    Excuse me, i'm a dumd ass!!!

    >>>>>>>>>>>>>
    glViewport(0, 0, dwWidth, dwHeight);

    // Set projection
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity( );

    gluOrtho2D(0.0, 1.0, 1.0, 0.0);

    // Set model view
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Clear the screen
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);

    // Bind the font texture
    Font.Bind();

    glEnable(GL_TEXTURE_2D);

    // Where to draw
    x := 0.0;
    y := 0.0;

    strText := 'Hello World!';
    n := Length(strText);

    // CORE
    glBegin(GL_QUADS);

    for i:=1 to n do
    begin
    c := strText[i];
    nc := Integer(c);

    // Texture coordinates
    u := (nc mod 16) / 16;
    v := 1 - ((nc div 16) + 1 )/ 16;

    glTexCoord2f( u, v + 1/16); glVertex2f( x, y);
    glTexCoord2f(u + 1/16, v + 1/16); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y);
    glTexCoord2f(u + 1/16, v); glVertex2f(x+1/MAX_CONSOLE_COLUMN, y+1/MAX_CONSOLE_ROW);
    glTexCoord2f( u, v); glVertex2f( x, y+1/MAX_CONSOLE_ROW);

    x := x + 1/MAX_CONSOLE_COLUMN;
    end;

    glEnd();

    // Flip back buffer to the framebuffer (screen)
    SwapBuffers(h_DC);
    <<<<<<<<<<<<<<<<<<<

    TheDD

Posting Permissions

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