Raylib 用俄语绘制文本

问题描述 投票:0回答:1

我正在尝试使用 DrawTextEx 函数以俄语显示文本。我最终得到的根本不是我想要的。 Display unicode。我正在使用 wchar_t,但编译器给出以下警告: raylib_unicode.c:27: warning: 来自不兼容指针类型的赋值。 这是代码:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

#include "raylib.h"

#define WINDOW_WIDTH    800
#define WINDOW_HEIGHT   600
#define TARGET_FPS      60

int main(int argc, char const *argv[])
{
    // setlocale(LC_ALL, "Russian");

    InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "unicode");

    wchar_t msg[] = L"Текст, Text.";
    Font font = LoadFontEx("resources/pt-mono_regular.ttf", 48, NULL, 0);

    SetTargetFPS(TARGET_FPS);

    while (!WindowShouldClose()) {
        BeginDrawing();

            ClearBackground(WHITE);

            DrawTextEx(font, msg, (Vector2) {(float) WINDOW_WIDTH / 2,
                        (float) WINDOW_HEIGHT / 2}, 48, 2, BLACK);

        EndDrawing();
    }

    UnloadFont(font);

    CloseWindow();

    return 0;
}

您能否指出我的错误,控制台中一切正常。

我使用了wchar_t。我期望正确的文本输出。

c unicode raylib
1个回答
0
投票

我将

wchar_t
更改为
char
,并在程序开头添加了以下代码:
int codepoints[512] = { 0 }; for (int i = 0; i < 95; i++) codepoints[i] = 32 + i; for (int i = 0; i < 255; i++) codepoints[96 + i] = 0x400 + i;
。 也将
NULL
中的
codepoints
更改为
LoadFontEx
。 完美运作。

© www.soinside.com 2019 - 2024. All rights reserved.