Page 1 of 4 123 ... LastLast
Results 1 to 10 of 31

Thread: OpenGL 3.2 and bitmap fonts

  1. #1

    OpenGL 3.2 and bitmap fonts

    Hello there.

    I was wondering - the documentation says that display lists and bitmaps are deprecated in OpenGL 3.2 core profile. Well then, how do we render bitmap fonts? I can't find any "new code" doing this - only the old snippets where display lists are involved.

    Do you happen to know anything in this matter?

  2. #2

    Re: OpenGL 3.2 and bitmap fonts

    Hi Brainer,
    I've never used display lists for fonts.

    I have taken an existing font (ttf, or other), and rendered it to a texture (using either Font Studio 4, or my own programs). I have then loaded into OpenGL the texture and just drawn quads or triangle strips (2 for each character) to the screen representing each character.

    I haven't used VBOs or vertex buffers like you should use in OpenGL 3+ (only used OpenGL 1.1 or 1.2 myself ATM), but only the usual glVertex2f() calls...

    cheers,
    Paul

  3. #3

    Re: OpenGL 3.2 and bitmap fonts

    Thanks for the idea, Paul. If you could paste some code here, I'd be glad.

  4. #4

    Re: OpenGL 3.2 and bitmap fonts

    The quickest way to do bitmapped fonts would be to get Font Studio 4.1

    http://web.archive.org/web/200806161...info.asp?id=12

    You should be also able to get the Font4.pas file from that site too so you can load and draw in OpenGL the font textures created by Font Studio

    If not, I can load the Font4.pas file somewhere so you can use it

    cheers,
    Paul

  5. #5

    Re: OpenGL 3.2 and bitmap fonts

    I can't find it, Paul. Can you please upload it somewhere?

  6. #6

    Re: OpenGL 3.2 and bitmap fonts

    I'm using built in bitmap generator myself so i don't have to provide applications with font picture files. Maybe you can pull something out of this function:

    [pascal]// You can call this with parameters such as
    // 'Courier',10,256
    // if fontSize is much bigger it will not fit well in 256 sized
    // texture, that is when you need to increase TexSize to 512
    procedure TNXFont.CreateBMP(fontName: string; fontSize,
    _TexSize: integer);
    var i,n,x,y: integer; b: TBitmap;
    begin
    self.TexSize:=_TexSize;
    nxTex.Options:=[toColorKey];
    nxTex.TransparentColor.r:=0;
    nxTex.TransparentColor.g:=0;
    nxTex.TransparentColor.b:=0;
    TextureI:=nxTex.AddTexture2('$'+fontname,'',true);
    b:=TBitmap.Create;
    b.Width:=TexSize; b.Height:=TexSize;
    sx:=texSize div 16; sy:=texSize div 14;
    with b.Canvas do begin
    pen.Color:=clBlack; brush.Color:=clBlack;
    rectangle(0,0,texSize,texSize);
    font.Name:=fontName; font.Size:=fontSize; font.Color:=clWhite;
    brush.Style:=bsClear; n:=0;
    pen.Color:=clRed;
    // First 32 characters (0..31) in ascii table are meaningless
    // They don't contain any characters used in texts.
    for i:=0 to 255-32 do begin
    // I save width in pixels of each character in charW[] array
    // This is used in rendering process
    charW[i+32]:=TextWidth(chr(i+32));
    if charW[i+32]>sx-1 then charW[i+32]:=sx-1;
    n:=n+TextHeight(chr(i+32));
    x:=sx*(i mod 16); y:=sy*(i div 16);
    TextRect(bounds(x,y,sx,sy),x+1,y,chr(i+32));
    end;
    CenterH:=n div ((255-31)*2);
    end;
    // At this point TBitmap b contains full font texture
    nxTex.LoadBMPData(@nxTex.texture[textureI],b);
    b.Free;
    end;[/pascal]

  7. #7

    Re: OpenGL 3.2 and bitmap fonts

    Quote Originally Posted by Brainer
    I can't find it, Paul. Can you please upload it somewhere?
    Here is the Font4.pas file:

    http://pastebin.com/eMgUHWRR

    I did comment out the loadjpgs method so I could get it running under Lazarus/freepascal though (I didn't need, or want it anyway)...

    I hope this helps

    cheers,
    Paul

  8. #8

    Re: OpenGL 3.2 and bitmap fonts

    Ok, thanks Paul - I'll take a rain check, 'cause another problem appeared.

    Before, I was using Vampire Imaging Lib for loading textures, but apperently it doesn't work with D2010. Is there a version for D2010? Or maybe you can suggest me another lib?

  9. #9

    Re: OpenGL 3.2 and bitmap fonts

    Perhaps you could try the freeimage image loading lib?

    http://freeimage.sourceforge.net/

    It is also free

    don't know if it is D2010 compatible though...

    cheers,
    Paul

  10. #10

    Re: OpenGL 3.2 and bitmap fonts

    I figured out that Vampyre is actually D2010 compatible...

    I have a question regarding rendering a quad in OGL 3.0. Let's say I have a quad like this:
    [code=delphi]
    glVertex3f(x, y, z);
    glVertex3f(x, y - pCharacter^.dy, z);
    glVertex3f(x + pCharacter^.dx, y - pCharacter^.dy, z);
    glVertex3f(x + pCharacter^.dx, y, z);
    [/code]
    Since quads are deprecated in OGL 3.0, I need to convert it to two triangles. How do I do that?

Page 1 of 4 123 ... LastLast

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
  •