The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Any way to render sdl_ttf without using sdl_surface?
ascaron50


Joined: 27 Mar 2016
Posts: 2
Location: RSA
is there a way to render text on the screen without using sdl_surface ?
something like just tell the renderer to draw the text on a certain position ?

What i'm trying to do is render text to a SDL_Texture(png image of a button);
Naith


Joined: 03 Jul 2014
Posts: 158
Well, you can always use a bitmap font to render your text, instead of using SDL_TTF. More information: http://lazyfoo.net/tutorials/SDL/41_bitmap_fonts/index.php
jsalina


Joined: 04 Jun 2014
Posts: 17
As far as I can tell the 2.0.14 SDL_TTF API render calls only return an SDL_Surface type. The underlying code would need to be modified to return an SDL_Texture.

If you really know what you're doing you can download the source code and make new versions of these that return an SDL_texture and re-compile.

extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg);
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,const char *text, SDL_Color fg);
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg);
jsalina


Joined: 04 Jun 2014
Posts: 17
FYI - I always use this to convert the surface to texture before rendering. I haven't found a quicker way short of what I described above.

SDL_CreateTextureFromSurface( SDL_Renderer, SDL_Surface );
Any way to render sdl_ttf without using sdl_surface?
Jonny D


Joined: 12 Sep 2009
Posts: 932
It sounds like he just wants a wrapper that does the work already.

Check out SDL_FontCache, one of my libraries:
https://github.com/grimfang4/SDL_FontCache



Jonny D




On Thu, Apr 7, 2016 at 10:44 AM, jsalina wrote:
Quote:
As far as I can tell the 2.0.14 SDL_TTF API render calls only return an SDL_Surface type. The underlying code would need to be modified to return an SDL_Texture.

If you really know what you're doing you can download the source code and make new versions of these that return an SDL_texture and re-compile.

extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Solid(TTF_Font *font, const char *text, SDL_Color fg);
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Solid(TTF_Font *font,const char *text, SDL_Color fg);
extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Solid(TTF_Font *font, const Uint16 *text, SDL_Color fg);


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Any way to render sdl_ttf without using sdl_surface?
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
I think a bigger question needs to be asked; what are you hoping to achieve by rendering to anything but `SDL_Surface*`?  If this is for some sort of optimization on your render calls, you might want to look into caching surfaces/textures so you're not building them from scratch each loop. 

On Thu, Apr 7, 2016 at 10:52 AM, jsalina wrote:
Quote:
FYI - I always use this to convert the surface to texture before rendering. I haven't found a quicker way short of what I described above.

SDL_CreateTextureFromSurface( SDL_Renderer, SDL_Surface );


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Any way to render sdl_ttf without using sdl_surface?
MrOzBarry


Joined: 26 Jun 2010
Posts: 620
I haven't test this, but I created a small library to manage caching text generated by TTF_RenderUTF8 called TextCache.  It does do some automation to convert the surface to a texture, and might achieve what you're after.

On Thu, Apr 7, 2016 at 11:34 AM, Alex Barry wrote:
Quote:
I think a bigger question needs to be asked; what are you hoping to achieve by rendering to anything but `SDL_Surface*`?  If this is for some sort of optimization on your render calls, you might want to look into caching surfaces/textures so you're not building them from scratch each loop. 

On Thu, Apr 7, 2016 at 10:52 AM, jsalina wrote:
Quote:
FYI - I always use this to convert the surface to texture before rendering. I haven't found a quicker way short of what I described above.

SDL_CreateTextureFromSurface( SDL_Renderer, SDL_Surface );


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org