Any way to render sdl_ttf without using sdl_surface?

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

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

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

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

It sounds like he just wants a wrapper that does the work already.

Check out SDL_FontCache, one of my libraries:

Jonny DOn Thu, Apr 7, 2016 at 10:44 AM, jsalina <jared.salina at gmail.com> wrote:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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 <jared.salina at gmail.com> wrote:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I haven’t test this, but I created a small library to manage caching text
generated by TTF_RenderUTF8 called TextCache
https://gist.github.com/mrozbarry/78282fdc0e855cf5a5b0c88ece352140. 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 <@Alex_Barry> wrote:

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 <jared.salina at gmail.com> wrote:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org