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
SDL 2.0 + SDL_ttf
joza404


Joined: 03 Jun 2013
Posts: 1
Hello everyone, recently I set the goal to migrate from SDL 1.2 to 2.0. Also I use SDL_ttf and that's the point: i tried to setup SDL_ttf but it complains of lack SDL.dll (remember, that we're using SDL2 already).
I think there is no point to deliver SDL2.dll with SDL.dll together.
What should I do? Even SDL_ttf 2.0.11 from here http://www.libsdl.org/projects/SDL_ttf/ complains of.

Thanks.
karimfikani


Joined: 18 Feb 2013
Posts: 5
Hey there, I had the same problem and I think SDL_ttf 2.0.11 needs to use SDL 1.2 at least that's what it says in the documentation. So I went with NeHe's tutorial http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/ and it works like a charm. SDL_ttf is using the free type fonts library so you might as well access it directly without SDL_ttf.
SDL 2.0 + SDL_ttf
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
I'm going through the SDL libraries I maintain and updating them for SDL 2.0.  I haven't gotten to SDL_ttf yet, but I should have a version soon.

For SDL 2.0 though I recommend going with a hardware accelerated font system, maybe something using OpenGL.


Cheers!



On Mon, Jun 3, 2013 at 3:35 PM, joza404 wrote:
Quote:
Hello everyone, recently I set the goal to migrate from SDL 1.2 to 2.0. Also I use SDL_ttf and that's the point: i tried to setup SDL_ttf but it complains of lack SDL.dll (remember, that we're using SDL2 already).
I think there is no point to deliver SDL2.dll with SDL.dll together.
What should I do? Even SDL_ttf 2.0.11 from here http://www.libsdl.org/projects/SDL_ttf/ complains of.

Thanks.


_______________________________________________
SDL mailing list

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

etfa


Joined: 02 May 2013
Posts: 4
Location: Paris
Hi everyone

i am also having troubles using SDL_ttf with SLD2.0, not at compilation but at execution time.
i don't know whether i should create a new discussion, please move it if need be.

what happens is that the surface created using the TTF_RenderText_Shaded() function doesn't look like it is usable by SDL2.0. (i also tried with the 'solid' version).

it throws a violation access exception when used by SDL_CreateTextureFromSurface().

i then tried to convert it to another format before i try to create a texture from it, creating an RGB surface and copying the text surface in it, but i got the same violation access error at the SDL_BlitSurface() function call.

here is my code:

Code:
void CMagivCtl::addProgressText(string str)
{
   int ret=0;
   SDL_Window *w_progress;
   SDL_Renderer* r_progress;
   //SDL_Rect dst_progress;
   
   TTF_Font *font_progress;

   SDL_Color text_color_progress = {0, 255, 255};
   SDL_Color text_color_2 = {1,234,45};

   log("entering %s",__FUNCTION__);

   w_progress = SDL_CreateWindow("opening...",
   SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
   445, 300,
   SDL_WINDOW_SHOWN | SDL_WINDOW_INPUT_FOCUS);

   r_progress = SDL_CreateRenderer(w_progress, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);

   log("%s: created renderer",__FUNCTION__);

   SDL_SetRenderDrawColor(r_progress, 0, 0, 0, 255);

   SDL_RenderClear(r_progress);

   SDL_RenderPresent(r_progress);

      // Load a font
   font_progress = TTF_OpenFont(POLICY_CLIBRIL.c_str(), 10);
   if (font_progress == NULL)
   {
      log("%s: TTF_OpenFont() Failed:  %d\n",__FUNCTION__,TTF_GetError);
   }

   

   SDL_Surface *surface = TTF_RenderText_Shaded(font_progress,"hello",text_color_progress,text_color_2);

   if (surface == NULL)
   {
      log("%s: error creating text surface",__FUNCTION__);
   }
   else
      log("%s: text surface created ok: %d, 0x%x",__FUNCTION__,surface,surface);


   SDL_Surface *recast = SDL_CreateRGBSurface(0,surface->w,surface->h,24,0,0,0,0);

   log("%s: surface w: %d, surface h: %d",__FUNCTION__,surface->w,surface->h);

   ret = SDL_BlitSurface(surface,NULL,recast,NULL);

   if(ret != 0)
      log("%s: error %d in blit surface: %s",__FUNCTION__,ret,SDL_GetError());
   

   SDL_Texture *texture = SDL_CreateTextureFromSurface(r_progress,recast);

   if(texture == 0)
      log("%s: unable to create texture: error: %s",__FUNCTION__,SDL_GetError());
   else
   {
      log("%s: texture created",__FUNCTION__);
      //SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
      ret = SDL_RenderCopy(r_progress,texture,NULL,NULL);
      if(ret < 0)
         log("%s: unable to copy texture to renderer: error: %s (%d)",__FUNCTION__,SDL_GetError(),ret);
      else
      {
         log("%s: texture copied to renderer",__FUNCTION__);

         SDL_RenderPresent(r_progress);

         SDL_DestroyTexture( texture );
         SDL_FreeSurface( recast );
         SDL_FreeSurface( surface );


      }
   }
}


I am implementing an ActiveX control using Visual Studio 8 under Windows7 (64bits)
I am using the SDL_VS2008.sln solution from the SDL-2.0.0-7046 package, and SDL_ttf-2.0.11 library.


what am i doing wrong?

in the previous post, sam talks about "hardware accelerated font system", and openGL.

could that solve my issue, or it is just for compilation issues?

thanks for your help, in advance.

Etienne
SDL 2.0 + SDL_ttf
Jonny D


Joined: 12 Sep 2009
Posts: 932
SDL_ttf works fine with SDL 2.0, you just have to recompile it with the SDL 2.0 headers (don't try to use SDL_ttf.dll with SDL2).  As Sam says, the result is still all SDL_Surfaces, but you can convert those to textures however you want.  Less than ideal for some applications, but just fine for now.

Jonny D



On Thu, Jun 6, 2013 at 12:59 AM, Sam Lantinga wrote:
Quote:
I'm going through the SDL libraries I maintain and updating them for SDL 2.0.  I haven't gotten to SDL_ttf yet, but I should have a version soon.

For SDL 2.0 though I recommend going with a hardware accelerated font system, maybe something using OpenGL.


Cheers!



On Mon, Jun 3, 2013 at 3:35 PM, joza404 wrote:


Quote:
Hello everyone, recently I set the goal to migrate from SDL 1.2 to 2.0. Also I use SDL_ttf and that's the point: i tried to setup SDL_ttf but it complains of lack SDL.dll (remember, that we're using SDL2 already).
I think there is no point to deliver SDL2.dll with SDL.dll together.
What should I do? Even SDL_ttf 2.0.11 from here http://www.libsdl.org/projects/SDL_ttf/ complains of.

Thanks.




_______________________________________________
SDL mailing list

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





_______________________________________________
SDL mailing list

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

etfa


Joined: 02 May 2013
Posts: 4
Location: Paris
ok thank Jonny, i'll try that and keep you posted.

Etienne
etfa


Joined: 02 May 2013
Posts: 4
Location: Paris
hi again

i just tried recompiling SDL_ttf-2.0.11 with SDL2.0 headers.

what i did is use the VS2008 solution supplied in the source package and change the 'additionnal include directories', the 'additionnal librairy directories' and 'additionnal dependencies' to use SDL2.lib.

of course, doing that i ran into obvious compilation errors while SDL_ttf is using SDL1.2 functions, definitions and else.

missing function is SDL_AllocSurface(), missing definition is SDL_SRCCOLORKEY

is there another version of SDL_ttf i should use?

by the way, i am now using the SDL-2.0.0-7125 snapshot.

Etienne
Re: SDL 2.0 + SDL_ttf
Sparks


Joined: 01 Jun 2013
Posts: 47
Sam Lantinga wrote:
I'm going through the SDL libraries I maintain and updating them for SDL 2.0.  I haven't gotten to SDL_ttf yet, but I should have a version soon.

For SDL 2.0 though I recommend going with a hardware accelerated font system, maybe something using OpenGL.

Cheers!

https://github.com/akrinke/Font-Stash Uses openGL and supports bitmap and truetype & UTF-8 Works pretty nicely for displaying text.