所以我试图将文字写入SDL_Window,但我无法显示文字。我尝试过使用不同的颜色和所有这些东西。
这是我的代码
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <GL/glew.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
if (SDL_Init(SDL_INIT_VIDEO) == (-1))
{
printf("Could not initialize SDL: %s.\n", SDL_GetError());
exit(-1);
}
int WINWIDTH = 640;
int WINHEIGHT = 480;
SDL_Window* window = SDL_CreateWindow("Text Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINWIDTH, WINHEIGHT, SDL_WINDOW_OPENGL);
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
TTF_Font* Sans = TTF_OpenFont("Fonts\\arial.ttf", 24);
SDL_Color White = { 255, 0, 0 };
SDL_Surface* surfaceMessage = TTF_RenderText_Solid(Sans, "put your text here", White);
SDL_Texture* Message = SDL_CreateTextureFromSurface(renderer, surfaceMessage);
SDL_Rect Message_rect;
Message_rect.x = 0;
Message_rect.y = 0;
Message_rect.w = 100;
Message_rect.h = 100;
SDL_RenderCopy(renderer, Message, NULL, &Message_rect);
system("pause");
exit(0);
}
我尝试了多种创建文本的方法,但都没有。