[SDL] SDL_ttf - a newbies question

Mark wilkinson.m at btopenworld.com
Mon Jan 3 07:12:52 PST 2005


Hi,

This is my first post here as I'm just beginning to learn SDL.  I've got SDL and
SDL_ttf installed, and (thanks to some great tutorials) I'm able to set up SDL
Video and SDL_ttf as follows:

	if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
            printf("Unable to init SDL: %s\n", SDL_GetError());


        screen = SDL_SetVideoMode(1024, 768, 16, SDL_SWSURFACE);

    
	if ( screen == NULL )
            printf("Unable to set 1024x768 video: %s\n", SDL_GetError());

	if(TTF_Init()==-1)
    	    printf("TTF_Init: %s\n", TTF_GetError());
	
	font=TTF_OpenFont("VeraSe.ttf", 16);

	if(!font)
 	    printf("TTF_OpenFont: %s\n", TTF_GetError());


All this (appears to) work ok, everything is initialised and a black window of
1024x768 appears.  However, when it comes to writing text onto the screen, I use
this:

    if(!(text_surface=TTF_RenderText_Solid(font,"Hello World!",clrWhite))) 
    {
	//handle error here, perhaps print TTF_GetError at least
	printf("SDL_ttf Error, %s\n", TTF_GetError());
    }

clrWhite is defined as 'SDL_Color clrWhite = {255,255,255,0};'

Is there something else I need to be doing before the text is displayed on
screen?  At the moment the screen stays resolutely blank.  Hope someone can help.

Mark





More information about the SDL mailing list