C only graphics, no library.

Started by
23 comments, last by Extrarius 18 years ago
I want to write a game strictly in C with no graphics library. Now do not jump the gun on how stupid that may sound. Yes I know 'C' has no graphics support, but the game I am looking to make does not really need any. A simple text only game of sorts, or more if it is possible. So of course I googled for awhile and the best I found was some minor control via printf() but the tutorial was less than one page and provided no explanations. Any got any idea's on where I can search for information on how to get minimal graphics out of C. Thanks, Halsafar
Advertisement
You can't. printf is as far as it goes. Anything else (colors, moving the cursor, clearing the screen) is OS-specific.
Got anything more on printf() graphical support.
I see it can apparently change video modes.
From there can I not print text out?


What you're looking for just isn't in ANSI C. As it's very machine/OS specific, it's not even mentioned in the standards. So as far as "no graphics library" goes, you'll definately need a terminal library. These terminal libraries can sometimes be very difficult to work with, terminals being archaic, confusing, hacked up beasts. Seriously, you might want to think about a graphics library, and if you're really in love with text, sprites or tiles with nothing but text.
Quote:Original post by Halsafar
Got anything more on printf() graphical support.
I see it can apparently change video modes.

No, it can't. Certain operating systems can use ANSI control codes to do things like that, but it isn't standard, so you may as well just use your OS-specific libraries to do console manipulation (they're a hell of a lot more user-friendly).
Okay, that is fine.
See I have played a lot of text only games from back in the day which I know where coded in 'C'. I wanted to make a super quick one. If I assume I am on DOS or Linux would that make life easier? Any links to a site which may explain more.


Any tutorial on how to use the terminal specific libraries?

Well, let's see. Linux and similar have a great console library called "curses" or "ncurses" (I forget the distinction), for which there is a tutorial available here. I believe that curses/ncurses is also available for Windows. There are also console functions in the Win32 API, documented here (somewhat more low-level).
If you're just interested in making a text game like Zork (rather than doing this to learn C) i'd recommend looking at something like the Inform programming language - which is specifically designed for making interactive ficition.

Otherwise, QHack is a simple roguelike intended to help people get started - it's source code is freely available.
Quote:Original post by Sneftel
You can't. printf is as far as it goes. Anything else (colors, moving the cursor, clearing the screen) is OS-specific.


I am not sure how much control you have if your in Linux but the address for the screen is B800:0000 and you can poke around in that memory location to get what you want.

I think the layout for the screen is: where each <...> is 1 byte

<attr><char><attr><char><attr><char>

or

<char><attr> etc...

You would need to experiment a bit as I have not done this for years..... As for the cursor on/off control... This you can do by writing directly to the ports or using your OS specific API function.

If you really wanted a text based game, i think that could easily be done with no libs at all, regardless of OS. Of course, all you get is text, but that's what you want right?

Instead of ncurses or equivilent, just output with printf() something like this:

"Select an option: [L]ook, [T]ake, [M]ove, se"

and wait for the user to press L, T, M, or U. Something like that. That's as barebones as it gets.

This topic is closed to new replies.

Advertisement