Udemy
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
Coding a console graphics library in C
New
18 students

Coding a console graphics library in C

Develop a classic mouse-controlled GUI for the terminal, a midlevel course for coders wanting to take the next step in C
Last updated 9/2026
English

What you'll learn

  • Learn to handle key-presses and mouse events in real time
  • Learn to use ANSI codes in order to control colors and the entire screen (with precision)
  • Learn to master pointers, structures and other advanced C features.
  • Learn to structure the project when creating a library to be used by other developers.

Course content

4 sections • 8 lectures • 5h 39m total length
  • Introduction0:38

Requirements

  • You need a basic understanding of the C language, the rest you will be taught here.

Description

Coding a console graphics library in C
Today we will begin writing our own (n)curses library. It is a library for making console graphics and in contrast with the regular console routines like printf() and scanf/fgets(), using a library like this you have full control over the screen.

Or at least as much as is possible. You can move around in a coordinate system, update individual characters, use foreground and background colors, the mouse and you can trigger on key presses which ie. makes it possible to move around with the arrow keys.


Putting things on the screen
In the 2nd and 3rd chapters, we'll be reading input from the keyboard. And that might not sound very interesting, but if you have used the standard C functions like scanf() or fgets() (or even read()), then you know how limited they are. You can read ascii characters but not special keys like the arrow keys and often you cannot even use the backspace key when you type.

Another severe limitation is that the functions only trigger when the user has entered a line of text and pressed the enter key. You can't make your code react instantly on the key-down event. Also, all key-presses are echoed to the screen, and that's not always what you want (for example in a game or when asked for a password).

We will solve all these limitations by writing our own keypress API. Our getch() function will react instantly on every keypress and it will successfully parse the arrow keys and backspace, without any echo to the screen (if you want the echo, you can print the character yourself). We will then use this custom API to control a cursor on the screen by using the arrow keys. Perhaps an early start of a gaming project or perhaps a text editor..?


Enroll now!
Or try out the free sample videos.


Sample
Here is a list of a few of the functions we'll be developing in this project:


private framebuffer *mkfb(int16);
public window *
mkwin(state*,int8,int8,int8*);
private state *
mkstate(void);

public _init void initlibrary(void);
public _fini void
exitlibrary(void);

private void sfblinear(window*,int8,int8,int8,int16);
private void
sfbxy(window*,int8,int8,int8,int8,int8);
private void
updatewin(window*,int8,int8,int8);

private void termenable(state*);
private void
termdisable(state*);

public void cputchar(window*,int8,int8,int8);
public void
cjump(window*,int8,int8);
public void
cupdate(window*);
public void
cframeset(window*,int8,int8,int8);

protected void ansimove(int8,int8);
protected int8 *
ansicolor(int8,int8);
protected int8 *
ansireset(void);
protected void
ansimode(void);

protected void showfb(framebuffer*,int16);
protected void
showwin(window*);
protected void
showstate(state*);

Who this course is for:

  • This course is for mid-level C programmers, wanting to take the next steps and write a graphics library.