Thread: Simple Ncurses-Style Text Graphics for Linux

  1. #1
    Registered User
    Join Date
    Jan 2016
    Location
    Kuwait
    Posts
    5

    Simple Ncurses-Style Text Graphics for Linux

    Hi Forum!

    I'm looking for a book, or howto, or tutorial or even a (well-documented) library that deals with displaying simple 2D text graphics in the Linux terminal, using C, in the style of lib-ncurses.

    My objective is learning, as I've found that I learn well when exploring a language using simple text based graphics as a start, and moving on from there.

    Any pointers and references would be greatly appreciated (pun not intended :-) ).

    Cheers,
    T.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Most people start with a google search with relevant terms such as "tutorial" and the topic of interest.
    https://www.google.co.uk/search?q=ncurses+tutorial
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Do you want the simple 2d character-based graphics to be particularly useful, or do you just want to experiment with drawing? If it's the latter just implement a simple "text window" using SDL and write your own routines.

  4. #4
    Registered User
    Join Date
    Jan 2016
    Location
    Kuwait
    Posts
    5
    Quote Originally Posted by Hodor View Post
    Do you want the simple 2d character-based graphics to be particularly useful, or do you just want to experiment with drawing? If it's the latter just implement a simple "text window" using SDL and write your own routines.
    Thanks, Hodor. SDL looks like it will do the trick: You don't need a whole X11 environment to o basic graphics with it, and the documentation looks solid.

  5. #5
    Registered User
    Join Date
    Jan 2016
    Location
    Kuwait
    Posts
    5
    Quote Originally Posted by Traiano View Post
    Thanks, Hodor. SDL looks like it will do the trick: You don't need a whole X11 environment to o basic graphics with it, and the documentation looks solid.
    Actually, looks like I'll have to take a step back and start with Libncurses. SDL most definitely requires a pre-existing windowing environment.

    Ncurses5 it is then ...

  6. #6
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by Traiano View Post
    Thanks, Hodor. SDL looks like it will do the trick: You don't need a whole X11 environment to o basic graphics with it, and the documentation looks solid.
    Yeah, give it a go. I have a particular fondness for character-based graphics and also pixel primitives like lines, circles, rectangles, etc (I think they're enlightening things to implement) so just give it a shot and ask questions here on the forum If you want to render text/characters I suggest using a VGA/monospace font (there are lots of public domain ones) and converting it to a C array (that's an additional project) so that you can easily build a simple bunch of functions to display text onto your SDL "canvas". To do this you'll have to first implement a function to set a pixel though, but that's easy with SDL. If you want a VGA font already converted to a C array I can probably give you one; each glyph is simply a w*h region in what's sometimes called a spritesheet. It's not the most efficient way to do things, but who cares

    Edit: You've posted another response. ncurses for the win! I wrote an entire "ascii art drawing library" (and others here might have as well), so go for it.

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    948
    You may also be interested in libcaca.

  8. #8
    Registered User
    Join Date
    Jan 2016
    Location
    Kuwait
    Posts
    5
    Quote Originally Posted by Hodor View Post
    Yeah, give it a go. I have a particular fondness for character-based graphics and also pixel primitives like lines, circles, rectangles, etc (I think they're enlightening things to implement) so just give it a shot and ask questions here on the forum If you want to render text/characters I suggest using a VGA/monospace font (there are lots of public domain ones) and converting it to a C array (that's an additional project) so that you can easily build a simple bunch of functions to display text onto your SDL "canvas". To do this you'll have to first implement a function to set a pixel though, but that's easy with SDL. If you want a VGA font already converted to a C array I can probably give you one; each glyph is simply a w*h region in what's sometimes called a spritesheet. It's not the most efficient way to do things, but who cares

    Edit: You've posted another response. ncurses for the win! I wrote an entire "ascii art drawing library" (and others here might have as well), so go for it.

    For the general benefit of all:

    For learning C through the medium of simple 2D graphics, using a library not requiring an X windowing environment on Linux/FreeBSD, AND well documented, Libncurses5/6 is great.
    To go with it, there is an excellent 579 page tutorial and reference called "The Programmer's Guide to Ncurses", and I highly recommend it :-)

  9. #9
    Registered User Bogdokhan's Avatar
    Join Date
    Jan 2016
    Location
    Belgium
    Posts
    8
    The following link is where I describe how to work with ncurses on windows (it's simpler under Linux) :
    How to run ncurses in a Windows environment - The Old Foundry

    And here is the link to ncurses 6 (since august) :
    https://www.gnu.org/software/ncurses/

  10. #10
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Ncurses also has example programs when you download the source distribution. When you install from your operating system's package manager, it's not always obvious where these are or how to locate them. Therefore I recommend going to the homepage and downloading the source directly.

  11. #11
    Registered User
    Join Date
    Jan 2016
    Location
    Kuwait
    Posts
    5
    Quote Originally Posted by christop View Post
    You may also be interested in libcaca.
    Ooo, this looks nice. Giving that a try as well!
    Last edited by Traiano; 01-30-2016 at 07:48 AM. Reason: typo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 18
    Last Post: 10-01-2015, 01:54 PM
  2. Replies: 1
    Last Post: 10-09-2014, 10:18 AM
  3. Portable, simple text-based graphics C library or stuff?
    By Mark Miller in forum C Programming
    Replies: 23
    Last Post: 09-24-2013, 05:34 AM
  4. Replies: 0
    Last Post: 03-26-2009, 02:47 PM
  5. sorting a doubly linked (linux-style) list
    By smoking81 in forum C Programming
    Replies: 4
    Last Post: 10-01-2008, 01:02 AM

Tags for this Thread