Thread: Blitting characters in graphics modes

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Exclamation Blitting characters in graphics modes

    Hi,
    I've been using this code (which is from "Teach Yourself Game Programming In 21 Days") to blit characters from the BIOS ROM font to the screen:-
    Code:
    unsigned char *screen = (unsigned char *)MK_FP(0xA000, 0);
    unsigned char far *rom_char_set = (char far *)MK_FP(0xF000, 0xFA6E);
    
    void Blit_Char(int x, int y, char c, int colour)
    {
       int offset, xc, yc;
       char far *work_char;
       unsigned char bit_mask = 0x80;
    
       work_char = rom_char_set + c * 8;
       offset = (y << 8) + (y << 6) + x;
       for (yc=0;yc<8;yc++)
       {
          bit_mask = 0x80;
          for (xc=0;xc<8;xc++)
          {
    	 if ((*work_char & bit_mask))
    	    screen[offset+xc] = colour;
    	 bit_mask = (bit_mask>>1);
          }
          offset += 320;
          work_char++;
       }
    }
    
    void Blit_String(int x, int y, int colour, char *string)
    {
       int index;
    
       for (index=0;string[index]!=0;index++)
          Blit_Char(x+(index<<3), y, string[index], colour);
    }
    The thing is, comparing it with a standard printf call, the characters look different, and the spacing between the characters seems a bit wayward. Does anyone know a way of emulating the printf function with transparent coloured text (i.e. for gaphics modes)?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    To solve that problem you're going to want a function that specializes on a certain platform. There are basically two types: functions that specialize on a specific routine on almost all platforms, and those that have general routiones (can do alot) but focus on one specific latform. printf specializes on sending only plain text, but it'll work in almost all situations. What you have right now works fine, so stick with that.

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I think the term 'blit' here necessitates that he does want to use printf() since that will also plot the 'uncolored' pixels of the cell. He wants to blit from the data in memory, when the pixel is 0 or blank, he will move on. When it is not blank, he will plot a pixel to the screen in the current color for the text. This will draw the text over an image, but will not show the cells of the characters.

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    so far as that goes... sorry to disappoint but i've yet to encounter a pixel granularity alteration method of the video display under text modes... after all, that's why they are called text... i'm sure you could edit the BIOS font characters themselves... but so far as anything further than that, i'm unsure... oh and by the way, is 80 by 25, per pixel, 640 by 480? or maybe 400... not too sure, but if it was i want to know...
    hasafraggin shizigishin oppashigger...

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Hey DA, in the code he has a pointer to A000:0000. So he is in graphics mode - he is just trying to read the ROM fonts so that he does not have to create his own.

  6. #6
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    oooh i see... well for my own bitmapped fonts what i did was output all the asciis, window the DOS box, take a screenshot, and read the windows bitmap into a bit mapped font file of my own... for your reference... but this might be an even better idea ... [tho i did get a nice turnout for my font... ]
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Counting the characters from each word from a text file
    By flipguy_ph in forum C Programming
    Replies: 6
    Last Post: 04-27-2009, 05:56 PM
  2. graphics programming idea
    By iain in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 01-18-2002, 08:41 AM
  3. Graphics won't print characters
    By cheesehead in forum C++ Programming
    Replies: 0
    Last Post: 11-12-2001, 11:45 AM
  4. Looking for feedback on graphics handling
    By The V. in forum Game Programming
    Replies: 2
    Last Post: 10-01-2001, 05:20 PM
  5. Getting started with 2d graphics.
    By NickB in forum Windows Programming
    Replies: 3
    Last Post: 08-22-2001, 11:40 AM