Is there any console "graphics" library for .Net?

23,355

Solution 1

http://msdn.microsoft.com/en-us/library/ms682073(v=VS.85).aspx

Some/many of these functions you might need to use P/Invoke for, but they should do what you need. You can write at arbitrary locations in the buffer and get key-based, non-buffered input. Usually you start with GetStdHandle() to get handles to the console input and output "streams" and then you call one of the appropriate functions from the above list to do something, like WriteConsoleOutputCharacter(), or PeekConsoleInput().

I once wrote a library to create an in-process windowing system using the Windows console and plain Win32 on C. Fun project, but I don't know where it is now.

Solution 2

You could try Curses-Sharp http://sourceforge.net/projects/curses-sharp/ or libtcod https://bitbucket.org/libtcod/libtcod

curses-sharp is a "A full featured, object-oriented, multi-platform C# wrapper for the curses terminal control library. "

and libtcod is "...a free, fast, portable and uncomplicated API for roguelike developpers providing an advanced true color console, input, and lots of other utilities frequently used in roguelikes."

Share:
23,355

Related videos on Youtube

nathanchere
Author by

nathanchere

I think, therefore I branch.

Updated on December 29, 2020

Comments

  • nathanchere
    nathanchere over 3 years

    My basic goal here is writing a .NET remake of Kingdom of Kroz. For those not familiar with the game:

    http://www.indiefaqs.com/index.php/Kingdom_of_Kroz

    http://www.youtube.com/watch?v=cHwlNAFXpIw

    Originally it was supposed to be a quick distraction project to give me a break from all the generic enterprise WCF/WF/LINQ2SQL/etc work projects occupying most of my time lately. While the result of my effort is playable, it looks like absolute arse (even for a console-based game) because of the way I'm redrawing everything in each frame.

    I'm aware of some alternate approaches but in the brief tests I've done they still don't offer significant performance or aesthetic benefits. I don't want to resort to a library which 'emulates' a console if I can help it. I'd prefer to work with the proper Win32 console API under the hood, but not to work with it directly if I can help it. Keeping in mind that it's a distinctly niche use case, what would be the 'generally' accepted best approach for this? Are there any particularly optimal console 'drawing' techniques one should be aware of? I don't mind swimming in a sea of PInvoke and marshalling as long as it still ends up with a fast, responsive and efficient console UI.

    • nathanchere
      nathanchere over 13 years
      Please try to avoid comments or "answers" along the lines of "just use proper graphics to mimic DOS display" or "why bother at all". The main learning point of this project was familiarity with the console.
    • Sam Saffron
      Sam Saffron over 13 years
      I like this question, my gut is telling me you will have to code it yourself using Console.SetCursorPosition and so on :(
  • nathanchere
    nathanchere over 13 years
    As far as I can tell the former doesn't work with the standard console and the latter isn't even .Net at all.
  • Vili
    Vili over 13 years
    Did you actually check it out? doryen.eptalys.net/2010/08/libtcod-1-5-1b1-released You can get the Windows/Linux32/OSX C# version in the download section
  • nathanchere
    nathanchere over 13 years
    I did but as far as I could tell it was just a C++ library using SDL / OpenGL to simulate a console, and the C# part is just a wrapper around that. I ideally want to use (and/or extend) the standard .Net console.
  • Vili
    Vili over 13 years
    Yes it's a wrapper, but I still would suggest that the libtcod is best way to get console-like application. It is used in several roguelike games which are classic ascii-based games just like Kingdom of Kroz.
  • Richard Stagg
    Richard Stagg over 13 years
    For speed and control, you won't achieve what you want without 1) this library or 2) API calls to the console (tomshardware.co.uk/forum/…) which would just complicate it. Functionality wise, you might need to write your own wrapper.
  • Agent_9191
    Agent_9191 over 13 years
    @FerretallicA Are you talking about the "standard .NET console" as System.Console? Curses-Sharp works with the standard console output, but once you start creating things like panels and windows System.Console becomes a major pain point.
  • nathanchere
    nathanchere over 13 years
    It's not quite what I was after but enough to get me started writing my own wrapper for it without much hard work so thanks!
  • siride
    siride over 13 years
    Unfortunately, that's what you have to use to do console "graphics" on Windows.
  • ashes999
    ashes999 almost 11 years
    I tried both of this. libtcod has more features/functionality, more colours, and much better performance; so that's what I went with.
  • fourpastmidnight
    fourpastmidnight over 9 years
    The site for libtcod has moved to here.