【问题标题】:How to make the SDL_ttf work with the SDL2?如何使 SDL_ttf 与 SDL2 一起工作?
【发布时间】:2020-05-04 23:23:50
【问题描述】:

我最近从 SDL 1.0 切换到了 2.0,以满足某些程序的需要。我已经成功地让它和我使用的 SDL_image 一样工作。但是,由于某种原因,SDL_ttf 2.0 不适用于我的程序。我已经注意使用2.0而不是1.0的功能,并用不是我自己的程序测试了ttf,没有任何效果。通常,程序会一直运行,直到它必须打印文本然后关闭并发送“进程返回 -1073741819”,这是因为我知道程序中的错误消息应该返回 0。我尝试了 x64 和 x86,但都没有工作x86 似乎提供了更好的结果。

#include <stdlib.h>
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>

int main()
{
  SDL_Surface *logo = NULL, *Wreed, *Reminder, *ecran = NULL;
  SDL_Window *window = NULL;
  SDL_Texture *textureLogo = NULL, *textureWreed = NULL, *textureReminder = NULL;
  SDL_Rect positionLogo = {1100/2 - 600/2, 700/2 - 600/2, 600, 600}, /*positionWreed,*/ positionReminder;
  TTF_Font *police = NULL;
  SDL_Color couleur = {0,0,0};
  SDL_Renderer* renderer;


police = TTF_OpenFont("arial.ttf", 40);

window = SDL_CreateWindow("Wreed Reminder", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1100, 700, SDL_WINDOW_OPENGL);
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
ecran = SDL_GetWindowSurface(window);

SDL_RenderClear(renderer);

Wreed = TTF_RenderText_Blended(police, "Wreed", couleur);
textureWreed = SDL_CreateTextureFromSurface(renderer, Wreed);
SDL_Rect positionWreed = {10, 10, 10, 10};
SDL_RenderCopy(renderer, textureWreed, NULL, &positionWreed);

SDL_RenderPresent(renderer);

SDL_Delay(5000);
}

如果有人知道如何解决这个问题,请帮忙。

【问题讨论】:

  • 请阅读How to Askminimal reproducible example。进行更改后,您是否进行了完整的重建?这是Windows系统吗?
  • 我确实重建了程序,它什么也没做,而且我确实使用了 Window 系统。对于这个问题,对不起,我不知道还能说什么。毕竟,我的问题是 SDL_ttf 2.0 不适用于 SDL2,不是吗?但是,如果您知道如何正确提问,我愿意接受建议。
  • 您的TTF_Init() 电话在哪里? “[TTF_Init()] 必须在使用此库中的其他函数之前调用,TTF_WasInit 除外。”
  • 为什么在使用之前不检查police是否为NULL?
  • 我询问 Windows 的原因是因为 search for that error code 出现了对文件系统错误的引用。

标签: c sdl-2 sdl-ttf


【解决方案1】:

好吧,我不太清楚发生了什么,但我重新安装了最新版本的 ttf 并设置了 x86 但它不起作用,所以我尝试了 x64,以防万一。也没有用。然后,我重置了 x86,令人惊讶的是,它正在工作。

【讨论】:

    猜你喜欢
    • 2016-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 1970-01-01
    • 2014-09-10
    相关资源
    最近更新 更多