[Solved] Best way of drawing text 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.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Fixed] Best way of drawing text in graphics mode

Post by Octacone »

Okay so after some coding I finally found how to do this. :D
Thank you all guys for helping me out. I decided to use an array of characters and pull my wanted character upon request. It works flawlessly. It supports all the features I wanted it to support. Now I just need to fill my master array with all those 100 characters.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Best way of drawing text in graphics mode

Post by Ch4ozz »

You gonna rewrite everything anyways if you want to support TTF later.
Static bitmap fonts are useless because they cant be scaled (they can using hqx algorithm which doesnt look too bad but its still a waste of power and memory), so it wont work in the long run with only one sized font.
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: Best way of drawing text in graphics mode

Post by onlyonemac »

octacone wrote:I only have 100 characters and I do not need more. So I just need to create 156 empty character with random names? :|
So I need to assign ASCII values to every each one of my 100 characters?
How are your characters currently identified? Because unless it's something that can easily be converted to ASCII by adding an offset to a numerical value, believe me you want to change that. Unless you can perform an array lookup to find the corresponding bitmap for each character, then you need to change the way your characters are identified otherwise your code is never going to be efficient. There's really no reason not to use ASCII.
octacone wrote:I can not do 8x8 or anything like that, my arrays are all different. I also need to pass Array size information and character width information to my internal method in order to draw a character.
Well however your bitmaps are represented, do:

Code: Select all

typedef struct
{
    // stuff for your bitmap here (size, pixels, etc.)
} character_bitmap;

character_bitmap font[256];

draw_character(char character, int x, int y)
{
    character_bitmap bitmap = font[character];
    draw_bitmap(bitmap, x, y); // however you're plotting the bitmap
}
Nothing really changes except the implementation of "character_bitmap".
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

[Solved] Best way of drawing text in graphics mode

Post by Octacone »

Well this issues has already been solved. I can display colored string and set their locations like so.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
Post Reply