Kopiuj
unsigned char *RenderTextToBuffer(int x,int y,int width, int height, char *text,int red,int green,int blue)
{
// Ustaw informacje o bitmapie (top-down, 32 bity)
BITMAPINFO bmi = { 0 };
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height; // top-down bitmapa
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
void* dibBits = nullptr;
HDC hdcScreen = GetDC(myconsole);
HDC hdcMem = CreateCompatibleDC(hdcScreen);
// Stwórz DIBSection, przypisz dane do `dibBits`
HBITMAP hBitmap = CreateDIBSection(hdcMem, &bmi, DIB_RGB_COLORS, &dibBits, NULL, 0);
HGDIOBJ oldBitmap = SelectObject(hdcMem, hBitmap);
// Wyczyść bufor - biały kolor
HBRUSH hBrush = CreateSolidBrush(RGB(0, 0, 0));
RECT rect = { 0, 0, width, height };
FillRect(hdcMem, &rect, hBrush);
DeleteObject(hBrush);
// Wybierz font
HFONT hFont = CreateFont(64, 32, 0, 0, FW_MEDIUM, FALSE, FALSE, FALSE, EASTEUROPE_CHARSET, OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE, (char*)("Arial"));
SelectObject(hdcMem, hFont);
// Kolor i tryb tła
SetBkMode(hdcMem, TRANSPARENT);
SetTextColor(hdcMem, RGB(red, green, blue)); // czarny
// Narysuj tekst
TextOut(hdcMem, x, y, text, strlen(text));
unsigned char* buffer = new unsigned char[width * height * 4];
// Skopiuj dane do naszego bufora
memcpy(buffer, dibBits, width * height * 4); // 4 bajty na piksel
// Sprzątanie
SelectObject(hdcMem, oldBitmap);
DeleteObject(hFont);
DeleteObject(hBitmap);
DeleteDC(hdcMem);
ReleaseDC(NULL, hdcScreen);
return buffer;
}
void TextOutXY(int x, int y, char* data,int red,int green,int blue)
{
/*SetTextColor(mydc, RGB(red, green, blue));
SetBkMode(mydc, TRANSPARENT);
TextOut(mydc, x, y, data, strlen(data));
SetBkMode(mydc, OPAQUE);*/
SIZE textSize;
GetTextExtentPoint32(mydc, data, strlen(data), &textSize);
Box2d(x, y, x + textSize.cx, y + textSize.cy);
unsigned char* image = new unsigned char[textSize.cx * textSize.cy * 4];
image=RenderTextToBuffer(x, y, textSize.cx, textSize.cy, data, red, green, blue);
for (int xp = 0; xp < textSize.cx; xp += 1)
{
for (int yp = 0; yp < textSize.cy; yp += 1)
{
//(px * 3 + (h - py) * w * 3);
//uint32_t pixel = image[yp * textSize.cx + xp];
//uint8_t r = (pixel >> 16) & 0xFF;
//uint8_t g = (pixel >> 8) & 0xFF;
//uint8_t b = pixel & 0xFF;
int index = xp*4+ yp* textSize.cx*4;
Color3iT(image[index], image[index+1], image[index+2]);
//Color3iT(r, g, b);
PutPixelT(xp+x ,yp+y);
}
}
delete[]image;
}