Advertisement

display text in sdl

Started by October 03, 2024 09:19 PM
7 comments, last by NubDevice 5 hours, 38 minutes ago

I am trying print text to the screen but I am getting compile errors. here is the code I am working on.

SDL_Surface* screen;
SDL_Surface* fontSurface;
SDL_Color fColor;
SDL_Rect fontRect;

SDL_Event event;

TTF_Font* font;

void fontInit()
{
	TTF_Init();
	font = TTF_OpenFont("arail.ttf", 12);
	fColor.r = 255;
	fColor.g = 255;
	fColor.b = 255;
}

void printF(char* c, int x, int y)
{
	fontSurface = TTF_RenderText_Solid(font, c, fColor);
	fontRect.x = x;
	fontRect.y = y;
	SDL_BlitSurface(fontSurface, NULL, screen, &fontRect);
	int SDL_Flip(SDL_Surface * screen);
}

pbivens67 said:
I am getting compile errors.

Read them carefully since they explain what's going on.

Advertisement

here is my errors

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _TTF_Init referenced in function "void __cdecl fontInit(void)" (?fontInit@@YAXXZ) Project94 C:\Users\Owner\source\repos\Project94\Project94\02_getting_an_image_on_the_screen.obj 1
Error LNK2019 unresolved external symbol _TTF_OpenFont referenced in function "void __cdecl fontInit(void)" (?fontInit@@YAXXZ) Project94 C:\Users\Owner\source\repos\Project94\Project94\02_getting_an_image_on_the_screen.obj 1
Error LNK2019 unresolved external symbol _TTF_RenderText_Solid referenced in function "void __cdecl printF(char *,int,int)" (?printF@@YAXPADHH@Z) Project94 C:\Users\Owner\source\repos\Project94\Project94\02_getting_an_image_on_the_screen.obj 1

You've posted about unresolved external symbols a few times before. The answer remains the same, except this time it is a different library.

I googled LNK2019 but I am still kind of lost. sorry for asking a dumb question

arial is misspelled.

Advertisement

I get an error printing “Hello” in printF function and SDL_Flip is undefined.

	printF("Hello",512, 384);
	
	
void printF(char* c, int x, int y)
{
	fontSurface = TTF_RenderText_Solid(font, c, fColor);
	fontRect.x = x;
	fontRect.y = y;
	SDL_BlitSurface(fontSurface, NULL, screen, &fontRect);
	SDL_Flip(screen);
}

research Function Scope.

check if screen is initialized or are you sure you're not missing a header in your File Scope.

Advertisement