Advertisement

display text in sdl

Started by October 03, 2024 09:19 PM
14 comments, last by pbivens67 2 months, 1 week 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.

Dev careful. Pixel on board.

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.

Dev careful. Pixel on board.

I have reworked my code but still cannot get text to print to the screen, here is my code

	SDL_Surface* display = NULL;
	TTF_Font* font;
	font = TTF_OpenFont(".ttf", 12);
	SDL_Surface* text;
	SDL_Color text_color = { 255,255,255 };
	text = TTF_RenderText_Solid(font, "Hello", text_color);
	SDL_BlitSurface(text, NULL, display, NULL);

I know I have left “arial” out of my code, I put it back in but it still does not work.

This topic is closed to new replies.

Advertisement