Over the past week I've been working on a roguelike game in C++ along with a friend. Mostly too learn the language.
I'm using:
- pdcurses
- Windows 7
- Visual studio C++
To output wchar_t
's wherever I want to in the console. I have succeeded in otuputting some unicode characters such as \u263B (☻), but others such as \u2638 (☸) will just end up as question marks(?).
Here's the relevant code I use for output.
// Container of room information
struct RoomInfo
{
wchar_t * layout;
int width;
int height;
};
// The following function builds RoomInfo
RoomInfo Room::examine(IActor * examinor)
{
RoomInfo ri;
ri.width = this->width;
ri.height = this->height;
ri.layout = new wchar_t[height * width];
for(unsigned int y = 0; y < height; y++)
{
for(unsigned int x = 0; x < width; x++)
{
ri.layout[y*width + x] = L'\u263B'; // works
//ri.layout[y*width + x] = L'\u2638'; // will not work
}
}
}
// The following function outputs RoomInfo
void CursesConsole::printRoom(RoomInfo room)
{
int w = room.width;
int h = room.height;
WINDOW * mapw = newwin(h, w, 1, 0);
for(int y = 0; y < h; y++)
{
wmove(mapw, y, 0);
for(int x = 0; x < w; x++)
{
int c = y*w + x;
waddch(mapw, room.layout[c]);
}
}
wrefresh(mapw);
delwin(mapw);
}
I could of course fall back on boring ANSI-characters. But it would be really awesome to have the complete unicode-set of characters to play with.
To sum it up: How do you make sure that unicode characters are outputted correctly?
Edit:
Ok, so I figured out my encoding is working correctly. The problem is that I need to force the terminal to switch to a more unicode-rich font face. Is there a cross-platform way to do this? is there even a windows specific way to do this?