SDL_ttf and hardware surfaces/double buffering?

i’m trying to get some text to the screen and i can get the SDL_ttf example code
to work but not in double buffered mode. does anyone know if it’s supposed to
work in that mode as well? if not, anyone have a fix/workaround/alternate
suggestion for simple text output to an opengl window?

thanks!

i’m trying to get some text to the screen and i can get the SDL_ttf example code
to work but not in double buffered mode. does anyone know if it’s supposed to
work in that mode as well? if not, anyone have a fix/workaround/alternate
suggestion for simple text output to an opengl window?

SDL_ttf just generates surfaces with the right pixels in them. It has no
knowledge of the different video modes. Therefore it works just fine
with every type of SDL surface and in every mode. The hard part is that
you have to figure out how to get the surfaces that SDL_ttf generates
onto the surface that you are going to see.

	Bob PendletonOn Wed, 2005-03-02 at 03:10 +0000, Jesse Kvatek wrote:

thanks!


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Bob Pendleton <bob pendleton.com> writes:

SDL_ttf just generates surfaces with the right pixels in them. It has no
knowledge of the different video modes. Therefore it works just fine
with every type of SDL surface and in every mode. The hard part is that
you have to figure out how to get the surfaces that SDL_ttf generates
onto the surface that you are going to see.

ah. ok, thanks for the clarification. (i’m a bit new at sdl, if you couldn’t
tell. :slight_smile:

i tried the following code snippet, trying to convert the sdl surface that
SDL_ttf gives me into a surface compatible with what i got from my initial video
setting call and then tried blitting it to my video surface, but it doesn’t
work. i get no errors or crashes, but i also get no text. is this (in general)
the right approach? (obviously, this is the exact approach since it doesn’t
work.)

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.

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 ) {
	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);

	SDL_FreeSurface(FontSurface);
	SDL_FreeSurface(FontBlit);
}

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