Hi,
I am trying to write unicode characters to the console using WriteConsoleOutput from the windows unit. I have code something like this:
uses
windows;
var
Buffer : array of TCharInfo;
hConsole : THandle;
...
hConsole := GetStdHandle(STD_OUTPUT_HANDLE);
...
procedure Draw(x, y : Integer; c : UnicodeChar; col : Word);
begin
Buffer[y*console.Width + x].UnicodeChar := c;
Buffer[y*console.Width + x].Attributes := col;
end;
procedure Update();
const
bufCoord : TCoord = (X:0; Y:0);
bufSize : TCoord = (Width:80; Height:30);
rectWindow : SMALL_RECT = (Left : 0; Top: 0; Right: 79; Bottom: 29);
begin
WriteConsoleOutput(hConsole, @Buffer[0], bufSize, bufCoord, rectWindow);
end;
The full code is of course somewhat longer but I am essentially following this C/C++ code to set up the console:
https://github.com/OneLoneCoder/videos/blob/master/olcConsoleGameEngine.hNow this works fine with ASCII characters, however it appears that characters wrap around once you hit 256. That is Drawing a character 65 ('A') is equal to drawing character 256+65, which suggests to me that this console is still drawing in ASCII mode, not in UnicodeChar mode. I am trying to draw the block characters from the above github link PIXEL_SOLID = 0x2588; PIXEL_THREEQUARTERS = 0x2593; ... but so far with no success. To draw a solid block I am trying:
Draw(x, y, #$2588, $0c0a);
I do have
{$mode objfpc}{$H+}
{$codepage utf8}
on the top of my files and I experimented with setting the code page with calls like
SetConsoleOutputCP(DefaultSystemCodePage);
SetTextCodePage(Output, DefaultSystemCodePage);
However, so far no success whatsoever.
Any ideas why my console only likes to show ASCII?