Page 1 of 1

chars in graphics mode..

Posted: Sat Jul 12, 2008 3:39 am
by asdfgh
how to write characters in graphics mode !!!!
i can jus plot pixel !!

Re: chars in graphics mode..

Posted: Sat Jul 12, 2008 5:19 am
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.)

Re: chars in graphics mode..

Posted: Sat Jul 12, 2008 5:39 am
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

Re: chars in graphics mode..

Posted: Mon Jul 14, 2008 4:52 am
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

Re: chars in graphics mode..

Posted: Mon Jul 14, 2008 4:57 am
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...

Re: chars in graphics mode..

Posted: Tue Jul 15, 2008 1:01 am
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 ;)