Hi there,
I am reasonbly new to programming and SDL, and for my game I need to display
text on screen so I decided to use the SDL_ttf library to try make it
easier.
I’ve been trying to write a function for it, but since the sdl_ttf
documentation is scant, I’m not having a great time. Here is the function:
int DrawTTF(TTF_Font *font, int x, int y, char *disptext)
{
SDL_Surface *text, *temp;
SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
font = TTF_OpenFont("Impact",12);
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
text = TTF_RenderText_Solid(font,disptext,white);
return(0);
}
What I want to do is pass in a x,y coordinate of where to put the text, and
also the text to pass in:
DrawTTF(font,300,300,“Hello! World”);
Unfortunatly, I am having no luck and was wondering if anyone knew a better
way to do it. The font face and size will be hard coded, so I dont’ care
about passing that stuff in, just a position on screen and a message.
Thanks for any help
Hi there,
I am reasonbly new to programming and SDL, and for my game I need to display
text on screen so I decided to use the SDL_ttf library to try make it
easier.
Have you looked at showfont.c?
See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment
Hi there,
I am reasonbly new to programming and SDL, and for my game I need to display
text on screen so I decided to use the SDL_ttf library to try make it
easier.
I’ve been trying to write a function for it, but since the sdl_ttf
documentation is scant, I’m not having a great time. Here is the function:
int DrawTTF(TTF_Font *font, int x, int y, char *disptext)
{
SDL_Surface *text, *temp;
SDL_Rect rect;
SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
font = TTF_OpenFont("Impact",12);
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
text = TTF_RenderText_Solid(font,disptext,white);
rect.x = x;
rect.y = y;
rect.w = text.w;
rect.h = text.h;
// Optionally: SDL_SetClipRect(screen_surface, &rect);
SDL_Blit(text, 0, screen_surface, &rect);
SDL_UpdateRect(screen_surface, 0, 0, 0, 0); // sloppy but simple
return(0);
}
Cheers,
–gmcnuttOn Thu, 2001-12-06 at 07:44, Tane Piper wrote:
Hey,
Thanks for your suggestions guys, but I got SFont working instead.
Hi there,
I am reasonbly new to programming and SDL, and for my game I need to
display> > text on screen so I decided to use the SDL_ttf library to try make it
easier.
Have you looked at showfont.c?
See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
You may be mixing up Debug and Release DLLs and LIBs. If you compile in Debug mode, it won’t link properly to Release LIBs, and vice versa.
The simplest solution is to just build SDL_ttf from source. Make sure the project settings match those of your game. Or just add the SDL_ttf source files directly into your Code::Blocks project.
If you post your compiler/linker output, we might be able to give a more detailed/precise answer.