Results 1 to 10 of 14

Thread: Text output pixel by pixel 8x8

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Text output pixel by pixel 8x8

    Hi, I wanted to hear what your suggestions are regarding the problem of text output if no font is available. I thought of an array which looks like this (e.g. A):
    Code:
    {0,0,0,0,0,0,0,0,
     0,0,0,1,1,0,0,0,
     0,0,1,0,0,1,0,0,
     0,1,0,0,0,0,1,0,
     0,1,1,1,1,1,1,0,
     0,1,0,0,0,0,1,0,
     0,1,0,0,0,0,1,0,
     0,0,0,0,0,0,0,0}
    etc. But I think that drawing always 64 pixels per character is a bit too time consuming.
    Any ideas?
    Ok, I think it will work if I update the screen after the complete text string is written. Since I can save a lot of time I might use the fontdata.inc of the Unit graph from Freepascal.
    It starts like this:
    Code:
    {******************************************}
    {  Bitmapped font data - unrolled for      }
    {  faster access. Each character is an     }
    {  8x8 byte array representing the full    }
    {  bitmap. 0 = nothing, 1 = color          }
    {******************************************}
    
    
    TYPE
      TBitMapChar = array[0..7,0..7] of byte;
    
    CONST
       DefaultFontData: Array[#0..#255] of TBitmapChar = (
    (
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0),
    (0,0,0,0,0,0,0,0)),
    ...
    So I can access the individual pixels via
    Code:
    DefaultFontData[char][x][y];
    Last edited by Cybermonkey; 30-10-2013 at 03:31 PM. Reason: New Idea
    Best regards,
    Cybermonkey

  2. #2
    Updating the screen takes a hellload of time. It's best to update after you're done, and - if your graph API allows it - only the parts that change. Since we're talking about low-res, I guess, if your characters are square enough, you could try converting the 8x8 map into a list of lines to draw from point ax,ay to bx,by. But I think nothing more than that.

  3. #3
    PGD Community Manager AthenaOfDelphi's Avatar
    Join Date
    Dec 2004
    Location
    South Wales, UK
    Posts
    1,245
    Blog Entries
    2
    I'm assuming it's an OpenGL based output mechanism. One option could be to render a texture from the data stored in your app so you effectively build a big in-memory image containing all the characters you have font data for in a nicely positioned location. And then simply use that as the source of textures for a series of polygons that are drawn when you want to draw the text.
    :: AthenaOfDelphi :: My Blog :: My Software ::

  4. #4
    Oh, sorry, I had to tell you that I am using SDL2 for this task.
    Best regards,
    Cybermonkey

  5. #5
    As Athena already pointed out making a predefined images/graphics for various charactes would be the best solution.
    To learn more about this process search the web for "Bitmap Fonts".
    Main advantage of Bitmap Fonts is that your font characters can actually be made from different colored pixels.
    The main disadvantage of Bitmap Fonts is that in order to scale them nicely you would wanna use several diferent sized images for each characters to not loose to much quality by scaling them.

  6. #6
    Yes, I know about bitmap fonts and will implement some functions for them. But I also want a "built-in" font which needn't to be loaded. So, yes, I want both.
    Best regards,
    Cybermonkey

  7. #7
    Pardon me but I don't see why you will even need "built in" font. You can achieve same results using Bitmap Fonts. You can even change fonts bitmap pixel bx pixel if that is what you need.
    Also wouldn't the use of "built in" font require you to render it pixel bx pixel which is much slower than rendering it as a whole graphics?

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
  •