Search code examples
csdl-2sdl-ttf

How to make the SDL_ttf work with the SDL2?


I've recently switch from SDL 1.0 to 2.0 for some program necessity. I've successfully managed to make it work as well as SDL_image that I use. However, for some reason, SDL_ttf 2.0 does not work on my program. I have paid attention to use the function of the 2.0 and not the 1.0 and tested the ttf with programs that weren't my owns, nothing worked. Usually, the program runs until it has to print text then it closes and send "process returned -1073741819" which is for what I know an error message in a program for it should return 0. I tried both x64 and x86 but none worked though the x86 seemed to give better results.

#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);
}

If anyone knows how to fix this, please help.


Solution

  • Well, I don't know quite what happened but I reinstalled the latest version of the ttf and set the x86 but it didn't work, so I tried x64, just in case. Didn't work either. Then, I reset the x86 and, surprise, it is working.