SDL_ttf无法正常运行
SDL_ttf doesn't run correctly
我正在使用SDL_ttf但在mingw32中,我下载了所有内容并尝试以下程序
#include <SDL.h>
#include "SDL_ttf.h"
#include <iostream>
using namespace std;
const int window_width = 600;
const int window_height = 600;
TTF_Font *font;
SDL_Surface *screen;
void init(void)
{
SDL_putenv("SDL_VIDEO_CENTERED=center");
if (TTF_Init() == -1)
{
cerr << "Unable to initialize SDL_tff: " << TTF_GetError() << endl;
exit(1);
}
font = TTF_OpenFont("arial.ttf", 12);
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) exit(2);
if ( (screen = SDL_SetVideoMode(window_width, window_height, 8, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) exit(3);
}
void drawText(SDL_Surface *screen, int x, int y, string text)
{
SDL_Color foregroundColor = { 255, 255, 255 };
SDL_Color backgroundColor = { 0, 0, 255 };
SDL_Surface *resulting_text;
SDL_Rect rect = { x, y, 0, 0 };
resulting_text = TTF_RenderText_Solid(font, text.c_str(), foregroundColor);
cout << SDL_GetError();
SDL_BlitSurface(resulting_text, NULL, screen, &rect);
SDL_FreeSurface(resulting_text);
}
void run()
{
SDL_Event event;
bool running = true;
while (running)
{
SDL_LockSurface(screen);
char s[256];
drawText(screen, 20, 20, "text ................");
SDL_UpdateRect(screen, 0, 0, window_width, window_height);
SDL_UnlockSurface(screen);
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
SDLKey _key = event.key.keysym.sym;
if ((_key == 27) || (_key == 'q') || (_key == 'Q'))
{
running = false;
}
}
}
}
}
int main(int argc, char* argv[]) { 初始化(); 运行(); }
好的,所以我在这里发布所有代码。我还将字体文件复制到当前文件夹,但它无效,也没有显示任何错误或警告。我使用以下命令在 mingw32 中编译它
g++ SDLTestFont.cpp -o TF.exe -I"d:SDLinclude" -lmingw32 -lSDLmain
lSDL SDL_ttf.lib -mwindows -O3 -w -static
看起来您的字体指针没有被初始化,并且您正在向rended_text传递垃圾。我会检查字体文件是否确实在您的项目文件夹中,并确保拼写准确。
我今天遇到了类似的问题SDL_ttf。您是否确保项目目录中有SDL_ttf的所有 DLL 文件?SDL_ttf附带的 DLL 文件。
相关文章:
- 如何让谷歌测试正常运行。测试总是失败。(它不会编译)
- 多线程程序卡在优化模式下,但在 -O0 中正常运行
- c++:if 语句无法正常运行,并继续执行无效输出
- 如何制作硬编码堆栈,而不是硬编码并保持程序正常运行
- 函数在正常运行时不起作用,但在调试时起作用
- 否则,如果语句无法正常运行
- 如果输入变量的数据类型与以前不同,如何使我的循环仍然正常运行?
- 我的程序运行良好,可以复制对象,但是当我使用复制分配(=)时,它仍然可以正常运行.为什么不给错误
- 在 Ubuntu 16.04 的 usr/local/bin 中安装的 c++ 应用程序在从主目录执行时无法正常运行
- SImple 代码在 DevC++ 中正确运行,但不能在 Visual Studio Code 中正常运行
- 断言语句无法正常运行
- 如何调试正常运行但在 ide 中返回分段错误的程序?
- 嵌套循环在重新函数内未正常运行
- 错误太多,智能感知引擎无法正常运行
- 为什么代码在 c++ 中无法正常运行
- 当我尝试为我的程序提供 3 个输入时,它需要 4 个才能正常运行.为什么
- BMP读取器无法正常运行
- 程序无法在 dev C++ 上正常运行
- C++ 程序将无法正常运行
- 为什么这个程序在Clang或GCC下不能正常运行?