I have been developing with SDL for a while now, but thought i needed another challenge. So I decided to draw some text on the screen using SDL_TTF.
I try to render the text at 0,0 but it is a bit below the screenborder. So that means it is not rendering fully at 0,0.
This code is just for testing purposes.
Here is the code I use at the time for testing:
#include <SDL.h>
#include <SDL_ttf.h>
#include <iostream>
int main(int argc, char* args[])
{
SDL_Texture* tex;
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window *win = SDL_CreateWindow("Font drawing test", 100, 100, 640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
TTF_Init();
while (true)
{
SDL_RenderClear(ren);
TTF_Font* font = TTF_OpenFont("./Resources/test.ttf", 72);
SDL_Surface *surf = TTF_RenderText_Blended(font, "Test", SDL_Color{ 255, 255, 255, 255 });
tex = SDL_CreateTextureFromSurface(ren, surf);
SDL_RenderCopy(ren, tex, NULL, new SDL_Rect{ 0, 0, 100, 100 });
SDL_RenderPresent(ren);
SDL_DestroyTexture(tex);
SDL_FreeSurface(surf);
TTF_CloseFont(font);
}
SDL_DestroyTexture(tex);
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
And this is how it looks on screen:
How can i fix this problem?
Marco