Category : sdl-ttf

I’m currently writing a gui and wanted to implement sdl_ttf to my project, the problem is font loading: no font wants to actually load, TTF_OpenFont errors with Error writing to datastream. bool gui::initalize() { if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("SDL_Init error: %sn", SDL_GetError()); return 1; } this->window = SDL_CreateWindow("Speller", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 800, 0); this->renderer ..

Read more

Here is a minimal example of how I render my SDL text: #include <SDL_ttf.h> void runttf() { constexpr auto SCREEN_WIDTH{300}; constexpr auto SCREEN_HEIGHT{300}; constexpr auto font_path = "/usr/share/fonts/truetype/fonts-beng-extra/MuktiNarrow.ttf"; //any font on your system constexpr SDL_Rect destination = {10,10,200,80}; constexpr SDL_Color text_color={0,0,0}; SDL_Init( SDL_INIT_VIDEO ); TTF_Init(); auto window = SDL_CreateWindow( "SDL TTF demo", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, ..

Read more

I’ve made a program with SDL2 and SDL_TTF, but when I run it, I get a blank white window which crashes in the space of few seconds. Here are the relevant parts of my code: Including the header files #include <SDL.h> #include <SDL_ttf.h> #include <string> #include <cstring> #include <vector> #include <iterator> #include <algorithm> The function ..

Read more

Here’s the code where I use TTF, trying to show simple text: //Main menu TTF_Font* titleFont; titleFont = TTF_OpenFont("PIXEBOY.ttf", 25); SDL_Color green = { 0, 255, 0 }; SDL_Surface* title; title = TTF_RenderText_Solid(titleFont, "SNAKE", green); SDL_RenderPresent(renderer); I get this exception: Unhandled exception at 0x7120212B (SDL2_ttf.dll) in SDL2 test.exe: 0xC0000005: Access violation reading location 0x00000004. What ..

Read more

I don’t have a code for the post or sth I was just wondering If I can Render small letters in my programs using fonts that have small letters inside, no matter what I write in the string quotes it appears to be Capital letter drawing as it is rendered on the screen. What are ..

Read more

I have issue with my code. It’s a function who take some parameters and display text on my window. But, if I have ‘n’ in my string, I gonna have a weird symbol and not my line-break. This is my code : void displayText(int posx, int posy, std::string text) { SDL_Surface* surfaceMessage = TTF_RenderText_Solid(_font, text.c_str(), ..

Read more

I’m trying to draw/highlight text in SDL2, there is the simple SDL_Surface *surf = TTF_RenderText_Blended(font, text, size); and then SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);, and then query the texture, and then draw the text, but this text adapts to kerning and is not all the same size (widths and heights). In doing so, I can’t ..

Read more