OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 11:38 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Draw a variable width psf glyph in the framebuffer
PostPosted: Sat Oct 08, 2022 3:51 am 
Offline

Joined: Fri Sep 02, 2022 11:36 am
Posts: 1
Ok so I've been working on this for days now, but I can't display a glyph on the framebuffer.
I was able to read the info in the psf header very well, and now I need to display some characters.
The problem with the wiki tutorial (https://wiki.osdev.org/PC_Screen_Font) is that it only deals with 8-bit wide fonts, while I would like to be able to support any psf font.

I came across this post: https://forum.osdev.org/viewtopic.php?f=1&t=41549&start=0. It describes my problem quite well, but even adapting my code with the remarks made there nothing works.

I also want to mention that I use a 12x24 font, and absolutely NOTHING appears on the screen when I try my putchar function (or I don't see it?)

Here is my code:
Code:
void fb_putchar(char c) {
  if (c == '\n')
    goto newline;
  int line;
  int bytesperline = font->width/32;
  int offset = (y_pos * font->height * pitch) +
        (x_pos * (font->width+1) * 4);

  u8 *glyph = (u8 *)&_binary_font_psf_start + font->headersize +
              c * font->bytesperglyph;
  serial_print("%x\n", glyph);
  for (u32 y = 0; y < font->height; y++) {
    line = offset;
    for (u32 x = 0; x < font->width; x++) {
      *((u32 *)(fb + line)) =
          glyph[x / 8] & (0x80 >> (x & 7)) ? fg_color : bg_color;
      line += 4;
    }
    glyph += bytesperline;
    offset += pitch;
  }
  x_pos++;
  if (x_pos >= width / 8) {
  newline:
    y_pos++;
    x_pos = 0;
    fb_putchar(' ');
  }
}


Does anyone notice a problem in my code, and is willing to help me?

Thank you very much, and I hope my post is correct, since it's the first one I'm doing here.


Top
 Profile  
 
 Post subject: Re: Draw a variable width psf glyph in the framebuffer
PostPosted: Tue Oct 11, 2022 10:10 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
Code:
  int bytesperline = font->width/32;

This is bytes per glyph line, right? If so, there are two problems: there are 8 bits per byte, not 32, and division rounds down but you need it to round up.

Code:
      *((u32 *)(fb + line)) =

What type is "fb"? You might be running into pointer arithmetic problems.

Code:
  if (x_pos >= width / 8) {

This looks like it might be wrong.

Code:
    fb_putchar(' ');

Why is this part of moving to the next line?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 112 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group