Original Post
I saw a few people were having trouble with it. So until Cone3D writes one of his tutes heres my main file. You need SDL_ttf and you can get it from the library sectin at http://www.libsdl.org/.
Thanks for the corrections Drizzt.
#include "SDL.h"
#include "SDL_ttf.h"
SDL_Surface *screen;
void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
SDL_BlitSurface(img, NULL, screen, &dest);
}
int main( int argc, char* argv[] )
{
TTF_Font* font;
//initialize systems
if (SDL_Init(SDL_INIT_VIDEO) <0)
{
printf("Unable to init SDL: %s\n", SDL_GetError());
return 1;
}
//set our at exit function
atexit ( SDL_Quit );
//create a window
screen = SDL_SetVideoMode ( 640, 480, 16, SDL_FULLSCREEN);
if (screen == NULL)
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}
TTF_Init ();
// Need the .ttf file in the same directory as
// the .exe or give it the full path.
font = TTF_OpenFont("Antqua.ttf", 20);
TTF_SetFontStyle (font, TTF_STYLE_NORMAL);
SDL_Color fg = {255,255,255,0};
SDL_Color bg = {255,0,255,0};
SDL_Surface *text1;
SDL_Surface *text2;
text1 = TTF_RenderText_Solid(font, "Hello World 1", fg);
text2 = TTF_RenderText_Shaded(font, "Hello World 2", fg, bg);
int done = 0;
//declare event variable
SDL_Event event ;
//message pump
while(done == 0)
{
DrawIMG(text1, 50, 100);
DrawIMG(text2, 200, 200);
//look for an event
while ( SDL_PollEvent ( &event ) )
{
//an event was found
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
}
}
SDL_Flip(screen);
}//end of message pump
//done
TTF_CloseFont(font);
// Don't forget to release the two text surfaces.
// I forgot the name of the function
return ( 0 ) ;
}
Edited by - Davaris on December 12, 2001 4:15:03 PM