[SDL] Re: SDL_ttf and hardware surfaces/double buffering?

Sebastian Beschke s.beschke at gmx.de
Tue Mar 8 13:47:10 PST 2005


jesse kvatek schrieb:
> also, m_Screen is the result of my initial video setting call:
> m_Screen = SDL_SetVideoMode( width, height, bpp, flags ) with flags = SDL_OPENGL 
> | SDL_RESIZABLE.

You can't blit surfaces to the screen when using OpenGL. Instead upload
the text as a texture and draw a quad with this texture.

>  
> 
> 	SDL_Surface *FontSurface, *FontBlit;
> 	SDL_Rect dstrect;
> 
> 	ScreenColor.r = 255;
> 	ScreenColor.g = 0;
> 	ScreenColor.b = 0;
> 
> 	FontSurface = TTF_RenderText_Solid(m_Font, text, ScreenColor);
> 	FontBlit = SDL_DisplayFormat(FontSurface);
> 	if ( text != NULL ) {

Shouldn't this be
	if(FontBlit != NULL)
?

> 		dstrect.x = 1;
> 		dstrect.y = 1;
> 		dstrect.w = FontBlit->w;
> 		dstrect.h = FontBlit->h;
> 		SDL_BlitSurface(FontBlit, NULL, m_Screen, &dstrect);

> 		SDL_UpdateRect(m_Screen, dstrect.x, dstrect.y, dstrect.w, dstrect.h);

With OpenGL, you need to use SDL_GL_SwapBuffers().

> 	
> 		SDL_FreeSurface(FontSurface);
> 		SDL_FreeSurface(FontBlit);

Better free those surfaces outside the if block.

> 	}

I'm not telling you about the deprecated SDL_OPENGLBLIT mode which
allows both blitting and using OpenGL. Don't use it. Use a textured quad
instead.

If you want, I can send you my font drawing OpenGl module. It's written
in D, but should be rather easy to convert to C++.
However, my module is also based on code posted here a few weeks ago by
Bob. You might search the archives for it.

-Sebastian





More information about the SDL mailing list