chars in graphics mode..

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
asdfgh
Member
Member
Posts: 42
Joined: Fri Apr 18, 2008 9:14 pm

chars in graphics mode..

Post by asdfgh »

how to write characters in graphics mode !!!!
i can jus plot pixel !!
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: chars in graphics mode..

Post by XanClic »

I think you have to do it with something like "font files". These would be files with a bitmap for every character you want to print. If you want to print a character, you look for its bitmap and then you draw this bitmap on the screen.

(I don't think that your hardware will do that for you if you thought there'ld be a buffer like 0xB8000 in text mode.)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: chars in graphics mode..

Post by Brendan »

Hi,
asdfgh wrote:how to write characters in graphics mode !!!!
i can jus plot pixel !!
One of the most efficient methods tends to go something like this (for 256 colour mode with 8 * 8 character data):

Code: Select all

    colourMask = colour << 24 | colour << 16 | colour << 8 | colour
    for(row = 0; row < 8; row++) {
        rowData = characterData[character][row];
        byteMask1 = conversionMask_8_to32[rowData][0];
        byteMask2 = conversionMask_8_to32[rowData][1];
        *(u32 *)screenAddress = (colourMask & byteMask1) | (*(u32 *)screenAddress & ~byteMask1);
        *(u32 *)(screenAddress + 4) = (colourMask & byteMask2) | (*(u32 *)(screenAddress + 4) & ~byteMask2);
        screenAddress += bytes_per_row;
    }
In this case the "characterData" array describes the 8 * 8 character, in one bit per pixel format. The "conversionMask_8_to32" is used to convert from "one bit per pixel" format into "one byte per pixel" format, so (for e.g.) if the byte of character data is 0010011b you end up with the pair of 32-bit values 0x0000FF00 and 0x0000FFFF. Finally, the boolean operations use these masks to set some pixels to "colour" and leave other pixels untouched.

Note1: If you want, you could pre-process the character data so that you can do "byteMask1 = characterData32[character][row][0];". Even though this reduces the number of table lookups done, it might make things slower due the cache locality (increased chance of cache misses).

Note2: This same basic technique can work really well with SSE or in long mode, especially if you unroll the loop.

Note3: This basic technique can be improved with bit shifting, to ensure that all accesses to/from display memory (or your video buffer) are aligned.

Of course "efficient" isn't the same as "high quality" - for high quality results you'd want to use variable width fonts based on vectors.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: chars in graphics mode..

Post by jal »

Brendan wrote:Note2: This same basic technique can work really well with SSE or in long mode, especially if you unroll the loop.
You are just teasing him aren't you? It's quite clear he hasn't got a clue about much, let alone about SSE or long mode :).


JAL
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: chars in graphics mode..

Post by suthers »

jal wrote:
Brendan wrote:Note2: This same basic technique can work really well with SSE or in long mode, especially if you unroll the loop.
You are just teasing him aren't you? It's quite clear he hasn't got a clue about much, let alone about SSE or long mode :).


JAL
Yah have a feeling he's one off those people who write a VESA driver without doing anything else then try and setup a form of TUI on it....
Brendan's being evil :twisted:
Jules

edit: corrected spelling...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: chars in graphics mode..

Post by pcmattman »

You are just teasing him aren't you? It's quite clear he hasn't got a clue about much, let alone about SSE or long mode
Maybe not *him*, but I'm sure someone else might stumble across this thread and read Brendan's post and figure out one of their problems. All it takes is a simple forum search ;)
Post Reply