ascii graphics in Windows

DarkForceRising

Senior member
Apr 16, 2005
407
0
71
Several semesters ago, I programmed a very basic version of Space Invaders in C, using the ncurses ascii library in Ubuntu Linux. I am now in a class where I have Visual C++, and can easily program in Windows. What I would like to know is if there is a comparable ascii graphics library for Windows. If possible, I want to port my little program over, but I don't know how.

Any suggestions?
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
You'd need to either a) find binaries for ncurses in win32 or b) compile from source.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
In "raw" Win32 you would create a window and a compatible offscreen bitmap buffer (for double-buffering), create a font (probably Courier New so it's fixed-width instead of proportional), then use TextOut to write the characters to the offscreen buffer.

Then you'd use a timer interrupt for triggering the screen updating.

I don't use .NET or Windows Forms at work, so I don't know what the equivalent logic would be for them.

There's also DirectX and XNA Game Studio (requires C#) if you wanted to get fancy.

CodeProject.com might have some sample code for animation / double-buffering and simple tutorials on win32 and forms text functions. Google can turn up more.

Petzold's Programming Windows is the bible of Win32 UI programming.
 

Sc4freak

Guest
Oct 22, 2004
953
0
0
I think he's looking more at a terminal-style ASCII art based game, rather than a fully fledged Win32 application.
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
Here's some code my brother sent me. Look up the functions on msdn.microsoft.com to get details, but this is a "library" he uses to draw console graphics:
PT_CGUI::pT_CGUI()
{
// Init the window stuff
hConsoleOut = GetStdHandle( STD_OUTPUT_HANDLE );
hConsoleIn = GetStdHandle( STD_INPUT_HANDLE );
GetConsoleScreenBufferInfo( hConsoleOut, &csbiInfo );

// Just cause
SetConsoleMode(hConsoleIn, ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT);
}
int PT_CGUI::getWidth()
{
return csbiInfo.dwSize.X;
}

int PT_CGUI::getHeight()
{
return csbiInfo.dwSize.Y;
}
void PT_CGUI::clearScreen()
{
for (int x = 0; x <= csbiInfo.dwSize.X; x++)
for (int y = 0; y <= csbiInfo.dwSize.Y; y++)
draw(x, y, ' ', 0x00);
}
int PT_CGUI::getKeyPress(bool& specialKey)
{
if (_kbhit() == 0)
return -1;

int input = _getch();

specialKey = false;
if (input == 0xE0) // Special key, like arrows
{
specialKey = true;
input = _getch();
}
return input;
}
void PT_CGUI::Draw(int x, int y, char c, WORD color)
{
COORD Coords;
DWORD Dummy;

Coords.X = x;
Coords.Y = y;

WriteConsoleOutputCharacter( hConsoleOut, &c, 1, Coords, &Dummy );
WriteConsoleOutputAttribute( hConsoleOut, &color, 1, Coords, &Dummy );
}
 

CTho9305

Elite Member
Jul 26, 2000
9,214
1
81
There's more, but I figured that would be enough to get you going, and my brother had to leave so he didn't send all the code. I thought I had a copy somewhere but couldn't find it.