Results 1 to 7 of 7

Thread: Font Display List

  1. #1

    Font Display List

    Hi again,

    Im having a few problems with rendering TTF fonts, they display ok on the screen, but they move across the X axis rapidly when ever i call render.

    I am probably missing something.. i have checked several sources on the net.

    Heres my Font code:
    Code:
    function TXGUITTFFont.BuildFont: Boolean;
    var
      Font: HFONT;
      _hdc: HDC;                                       
    begin
      _hdc := wglGetCurrentDC;
      If GlID > 0 Then glDeleteLists(GlID, 96);
      GlID := glGenLists(96);                      
      Font := CreateFont(-24,                      
                          0,                                  
                          0,                                  
                          0,                                  
                          FW_BOLD,                      
                          0,                                  
                          0,                                  
                          0,                                  
                          ANSI_CHARSET,                      
                          OUT_TT_PRECIS,                     
                          CLIP_DEFAULT_PRECIS,               
                          ANTIALIASED_QUALITY,               
                          FF_DONTCARE or DEFAULT_PITCH,
                          'Courier New');                     
      SelectObject(_hdc, Font);                                
      wglUseFontBitmaps(_hdc, 32, 96, GlID);                
      Result := True;
    end;
    
    destructor TXGUITTFFont.Destroy;
    begin
      If GlID > 0 Then glDeleteLists(GlID, 96);
      inherited Destroy;
    end;
    
    function TXGUITTFFont.LoadFromFile(const Filename: String): Boolean;
    begin
      Result := BuildFont;
    end;
    
    procedure TXGUITTFFont.Render(const X,Y,Z: Single; const Value: String);
    begin
      If Value = '' Then Exit;                                
      glPushMatrix;
        glTranslatef(X, Y, Z);
        glPushAttrib(GL_LIST_BIT);                          
          glListBase(GlID-32);                                  
          glCallLists(Length(Value), GL_UNSIGNED_BYTE, PChar(Value));
        glPopAttrib;
      glPopMatrix;                                  
    end;
    When i render the object i go through a loop,

    Ortho On
    glPushMatrix;
    Render Controls

    glPushMatrix;
    Render Cursor
    Render sample text (Cursor position)
    glPopMatrix;
    glPopMatrix;
    Ortho Off

    I cant see any where whats wrong, i checked if there's an extra Push/Pop matrix but cant find anything.

    Any help will be great
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    Font Display List

    I'm not entirly sure how your problem is ment to look, and I don't use TTFFont in OGL. What do you mean by:

    but they move across the X axis rapidly when ever i call render.

    Maybe your giving the wrong value for X. Do you reset to the identity when changing to Ortho mode?

  3. #3

    Font Display List

    I'm not entirly sure how your problem is ment to look, and I don't use TTFFont in OGL. What do you mean by:

    but they move across the X axis rapidly when ever i call render.
    I mean, when the cursor (GUI) is moved over my window (GUI) control, text is supposed to appear under the cursor (much like a hint), however the text appears at the very bottom of the window, and scrolls along the x axis all the way off the screen, very fast.

    Maybe your giving the wrong value for X. Do you reset to the identity when changing to Ortho mode?
    i have tried to render the text at point 0,0 and i have then tried 100,100 and it doesnt seem to make a difference.

    I have tried it with and without glLoadIdentity.
    I do call glPushMatrix and glpopMatrix when rendering each control, would this effect it?

    It doesnt effect any other controls, just this 1 thing?!

    I have uploaded the current release on my site http://www.pulse-soft.oneuk.com/inde...ilscube|phase7

    as the program loads, make sure the cursor is not in the SDL window, once it has loaded, as soon as you move the cursor into any of the forms text will appear at the bottom of the screen, and disapears off to the right of the screen.
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    Font Display List

    In that case I would look at the code you use to render the mouse cursor. It sounds like it is accumulating the mouse X coordinate each frame and not setting the matrix back to the previous state. The text moving off screen is just a symptom of a problem elsewhere.

  5. #5

    Font Display List

    I cant see any problems, or maybe im going blind.

    Im using translatef to position the cursor, heres the code:
    Code:
      glPushMatrix;
        glTranslatef&#40;X, Y, 0&#41;;
    
        _XGUISkins.RenderElement&#40;'xcursor', 'normal'&#41;;
        If fOControl <> Nil Then
        Begin
            cn &#58;= fOControl.Propertise.GetStr&#40;'@classname', ''&#41;;
            w &#58;= Length&#40;cn&#41;;
            h &#58;= 14;
            glColor4f&#40;0.5, 0.5, 1.0, 1.0&#41;;
            glBegin&#40;GL_QUADS&#41;;
              glVertex2f&#40;&#40;14/2&#41;, &#40;14/2&#41;&#41;;
              glVertex2f&#40;&#40;14/2&#41;, &#40;14/2&#41;+h&#41;;
              glVertex2f&#40;&#40;14/2&#41;+w, &#40;14/2&#41;+h&#41;;
              glVertex2f&#40;&#40;14/2&#41;+w, &#40;14/2&#41;&#41;;
            glEnd;
            _XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;&#40;14/2&#41;+1, -&#40;&#40;14/2&#41;+1&#41;, cn&#41;;
        End;
      glPopMatrix;
    I have changed from:
    Code:
    _XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;&#40;14/2&#41;+1, -&#40;&#40;14/2&#41;+1&#41;, cn&#41;;
    To:
    Code:
    glPopMatrix;
    _XGUIFonts.Items&#91;_XGUIFonts.Count-1&#93;.Render&#40;0, 0, cn&#41;;
    yet the problems still the same?
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  6. #6

    Font Display List

    Note that the raster positions of OpenGL always starts from the bottom-left and not from the top-right as in delphi vcl.

    You can however via the perspective calculations flip the coordinates for glVertex and so forth, but not for the raster.

    When i found out this i ditched the truetype fonts in OpenGL and went for textured bitmap fonts instead.
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  7. #7

    Font Display List

    Ok thanks for your help..
    I have given up with GL Fonts, and stuck with BMP fonts.

    I was mainly playing with GL Fonts to see what i can do with it, but its not really worth the hassel over a 1meg file.
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

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