0

I have a set_pixel function (a function that sets the color of a pixel in a example display), and I only have this method of output to print to a display.

I was trying to print some characters to the screen for debugging and other general purposes, but the only way I found to accomplish this is by printing each letter pixel by pixel, a very slow and tedious thing, considering that I will use uppercases and numbers.

For example, this is some code used to print a 'A' with a simple set_line function made up with the set_pixel function.

void draw_A(int x, int y, int charWidth, int charHeight, int RGB)
 {
    //first draw a line along the left side:
    set_line(x, y, x, y+charHeight,RGB);
    //draw a line across the top:
    set_line(x,y,x+charWidth,y,RGB);
    //draw a line along the right side:
    set_line(x+charWidth,y,x+charWidth,y+charHeight,RGB);
    //finally close in the box half way up
    set_line(x,y+(charHeight/2),x+charWidth,y+(charHeight/2),RGB);
 }

For this I'm using C as my language in a freestanding environment, without the standard libraries, like <stdio.h> or any kind of library, but I could re-implement something I guess or port some libraries.

How I can accomplish this without going pixel by pixel or line by line? Thanks in advance!

Rottenheimer2
  • 425
  • 1
  • 5
  • 13
  • 1
    Ultimately, under the stated conditions, you will have to set each pixel. You would need to develop some routines that can draw lines or fill areas, and you can then define letters in terms of lines or areas to be filled. – Jonathan Leffler Dec 11 '17 at 15:44
  • What exactly do you mean by "going pixel by pixel"? Please show some of your code that does it. – n. m. could be an AI Dec 11 '17 at 15:59
  • @AnttiHaapala What would you use then? – Rottenheimer2 Dec 11 '17 at 16:54
  • @JonathanLeffler that line approach look more pleasant to do than the set_pixel approach, I will try right now. – Rottenheimer2 Dec 11 '17 at 16:55
  • @n.m. I'm adding an example in the question. – Rottenheimer2 Dec 11 '17 at 16:59
  • Don't reinvent the wheel. There are many many image libraries that do this. – Barmak Shemirani Dec 11 '17 at 18:28
  • @BarmakShemirani can you give me an example please? – Rottenheimer2 Dec 11 '17 at 18:54
  • 2
    You want to be able to "render" "glyphs" from a "font". (All quoted words are terms you should familiarise yourself with). If you device is small, perhaps you want to implement a rasterised (bitmapped) font of a fixed size or two. If it is big and powerful enough to contain a scalable font implementation, there are many of those (freetype2 is a popular one). A simple homebrew vector-based font (straight lines only) is another option. In any case, character shapes should be **data**, not code. – n. m. could be an AI Dec 11 '17 at 21:52
  • Sorry, I didn't read your requirements where you say you can't use anything, not even `` – Barmak Shemirani Dec 11 '17 at 23:02

0 Answers0