SDL_ttf

shouldn’t TTF_Init be called before TTF_OpenFont?On Fri, Nov 26, 2010 at 3:19 PM, Andreas Schiffler wrote:

Things that come to mind:

  • add SDL_Init
  • check font for NULL

The “official” sample code you can use as reference can be found here:
http://hg.libsdl.org/SDL_ttf/file/c1f5f19d8fa9/showfont.c

–Andreas

On 11/26/10 9:54 AM, Lars Br?mer wrote:

Hi List,

its quiet an expert list and I feel a little clumbsy to post here…
Anyway :slight_smile:

I`ve got Vsiual C express working.
It compiles SDL programms and it can make use of the SDL_mixer(the sound
mixer).

I think I have included the SDL_ttf files at the right location because it
seems pretty much
the same procedure than SDL_mixer.

The includes and the SDL_ttf initialisation works.
But when I start with

text = TTF_RenderText_Solid( font, “Space…”, textcolor );

The program compiles, links, starts but

I got an exeption and a untreated access

Unbehandelte Ausnahme bei 0x6f4c27f4 in TTF_test.exe: 0xC0000005:
Zugriffsverletzung beim Lesen an Position 0x00000000.

(sorry its German)

Here is a minimum program to document my trouble…
It has not even the text blitted and it stops where the trouble starts :slight_smile:


#include “stdafx.h”
#include “TTF_test.h”
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include “SDL_ttf.h”

int main(int argc, char *argv[])

{
?? SDL_Surface? *screen;
?? SDL_Surface *text = NULL;
?? TTF_Font *font;
?? SDL_Color textcolor? = { 128, 88, 77 };

?? //font=TTF_OpenFont(“font.ttf”, 16);
?? font=TTF_OpenFont(“C:/winnt/Fonts/Verdana.ttf”,18);? // both works

?? screen = SDL_SetVideoMode(640, 480, 24,SDL_SWSURFACE);

?? TTF_Init();

?? //When I uncomment this line, the error happens…so far it works
? //text = TTF_RenderText_Solid( font, “Space…”, textcolor );

? SDL_Delay(500);

? TTF_CloseFont(font);
? TTF_Quit();
}


It would be very nice if somebody could have a look on it because I like to
do something on alternate OS

and SDL seems to be a very nice API.

Thanks you very much,

Lars


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


David

Yes, and you’ll need to check for TTF_Init returning errors as well.On Fri, Nov 26, 2010 at 3:04 PM, David Roguin wrote:

shouldn’t TTF_Init be called before TTF_OpenFont?

On Fri, Nov 26, 2010 at 3:19 PM, Andreas Schiffler wrote:

Things that come to mind:

  • add SDL_Init
  • check font for NULL

The “official” sample code you can use as reference can be found here:
http://hg.libsdl.org/SDL_ttf/file/c1f5f19d8fa9/showfont.c

–Andreas

On 11/26/10 9:54 AM, Lars Br?mer wrote:

Hi List,

its quiet an expert list and I feel a little clumbsy to post here…
Anyway :slight_smile:

I`ve got Vsiual C express working.
It compiles SDL programms and it can make use of the SDL_mixer(the sound
mixer).

I think I have included the SDL_ttf files at the right location because it
seems pretty much
the same procedure than SDL_mixer.

The includes and the SDL_ttf initialisation works.
But when I start with

text = TTF_RenderText_Solid( font, “Space…”, textcolor );

The program compiles, links, starts but

I got an exeption and a untreated access

Unbehandelte Ausnahme bei 0x6f4c27f4 in TTF_test.exe: 0xC0000005:
Zugriffsverletzung beim Lesen an Position 0x00000000.

(sorry its German)

Here is a minimum program to document my trouble…
It has not even the text blitted and it stops where the trouble starts :slight_smile:


#include “stdafx.h”
#include “TTF_test.h”
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include “SDL_ttf.h”

int main(int argc, char *argv[])

{
?? SDL_Surface? *screen;
?? SDL_Surface *text = NULL;
?? TTF_Font *font;
?? SDL_Color textcolor? = { 128, 88, 77 };

?? //font=TTF_OpenFont(“font.ttf”, 16);
?? font=TTF_OpenFont(“C:/winnt/Fonts/Verdana.ttf”,18);? // both works

?? screen = SDL_SetVideoMode(640, 480, 24,SDL_SWSURFACE);

?? TTF_Init();

?? //When I uncomment this line, the error happens…so far it works
? //text = TTF_RenderText_Solid( font, “Space…”, textcolor );

? SDL_Delay(500);

? TTF_CloseFont(font);
? TTF_Quit();
}


It would be very nice if somebody could have a look on it because I like to
do something on alternate OS

and SDL seems to be a very nice API.

Thanks you very much,

Lars


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yes, and you’ll need to check for TTF_Init returning errors as well.

Things that come to mind:

  • add SDL_Init
  • check font for NULL

Hello,

Yes , indeed some not so bright mistakes. Unfortunately, even if I have now
fixed the order of the
function calls, I have the same results .

Always the exception. And its true I should check the return values.

Here is the beginning of the crux. I am actually doing the ttf thing to
print out
some results just on the screen to check the varible values, hence
I have trouble to create the stderr, respective the stdout.

Using the GNU compiler…no problem but since I switched on visual c
I have trouble here. The files seem not to be created or to closed and
deleted just after the app
has finished.

Using Andreas hint and compiling the “official” demo brought also no good
results.
The compiler complains that he cant resolve the ttf functions.

Still wondering why I could make the sdl_mixer get to work and cant do this
:frowning:
Anyway, thank you so far for looking at it.

I attached the improved basic ttf program, like I said even without
blitting.

It seems more and more that my mistake comes from the setup.
Are there any known problems with FreeType2 in this matter?

Thanx so far,
Lars

#include “stdafx.h”
#include “TTF_test.h”
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include “SDL_ttf.h”

int main(int argc, char *argv[])

{

SDL_Surface *screen;
SDL_Surface *text = NULL;
TTF_Font *font;
SDL_Color textcolor = { 128, 88, 77 };

if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0)
 exit (-1);

atexit (SDL_Quit);

TTF_Init();

//font=TTF_OpenFont(“font.ttf”, 16);

font=TTF_OpenFont(“C:/winnt/Fonts/Verdana.ttf”,18); // both works

screen = SDL_SetVideoMode(640, 480, 24,SDL_SWSURFACE);

//When I uncomment this line, the error happens…so far it works
text = TTF_RenderText_Solid( font, “Space…”, textcolor );

SDL_Delay(500);

TTF_CloseFont(font);
TTF_Quit();
}

What does TTF_Init return? It sounds like maybe it can’t find a dll.

Try changing
TTF_Init();

to :

int result = TTF_Init();
printf(“TTF_Init returned %d\n”, result);
getch();

and run the compiled .exe from a command line window. That should tell
you if there’s an error and what it is.On Sat, Nov 27, 2010 at 5:07 AM, Lars Br?mer wrote:

Yes, and you’ll need to check for TTF_Init returning errors as well.

Things that come to mind:

  • add SDL_Init
  • check font for NULL

Hello,

Yes , indeed some not so bright mistakes. Unfortunately, even if I have now
fixed the order of the
function calls, I have the same results .

Always the exception. And its true I should check the return values.

Here is the beginning of the crux. I am actually doing the ttf thing to
print out
some results just on the screen to check the varible values, hence
I have trouble to create the stderr, respective the stdout.

Using the GNU compiler…no problem but since I switched on visual c
I have trouble here. The files seem not to be created or to closed and
deleted just after the app
has finished.

Using Andreas hint and compiling the “official” demo brought also no good
results.
The compiler complains that he cant resolve the ttf functions.

Still wondering why I could make the sdl_mixer get to work and cant do this
:frowning:
Anyway, thank you so far for looking at it.

I attached the improved basic ttf program, like I said even without
blitting.

It seems more and more that my mistake comes from the setup.
Are there any known problems with FreeType2 in this matter?

Thanx so far,
Lars

#include “stdafx.h”
#include “TTF_test.h”
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
#include “SDL_ttf.h”

int main(int argc, char *argv[])

{

?SDL_Surface ?*screen;
?SDL_Surface *text = NULL;
?TTF_Font *font;
?SDL_Color textcolor ?= { 128, 88, 77 };

? if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0)
? ?exit (-1);
?atexit (SDL_Quit);

? TTF_Init();
?//font=TTF_OpenFont(“font.ttf”, 16);

?font=TTF_OpenFont(“C:/winnt/Fonts/Verdana.ttf”,18); ?// both works

?screen = SDL_SetVideoMode(640, 480, 24,SDL_SWSURFACE);

?//When I uncomment this line, the error happens…so far it works
?text = TTF_RenderText_Solid( font, “Space…”, textcolor );

?SDL_Delay(500);

?TTF_CloseFont(font);
?TTF_Quit();
}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

What does TTF_Init return? It sounds like maybe it can’t find a dll.
The result is 0.

Try changing
TTF_Init();

to :

int result = TTF_Init();
printf(“TTF_Init returned %d\n”, result);
getch();

Is font null after the TTF_OpenFont call?On Sat, Nov 27, 2010 at 6:51 AM, Lars Br?mer wrote:

What does TTF_Init return? It sounds like maybe it can’t find a dll.

The result is 0.

Try changing
TTF_Init();

to :

int result = TTF_Init();
printf(“TTF_Init returned %d\n”, result);
getch();


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

yes, it is.>Is font null after the TTF_OpenFont call?

If font is NULL after the TTF_OpenFont() call then it isn’t finding the
font, or if it is finding it, it isn’t able to use the FreeType library
properly to load the TTF file. The reason it crashes when you uncomment the
line to draw with the font is that the font variable is NULL.

Best advice is to get the ShowFont sample application working. It should
work out of the box. Make sure you have you SDL related DLL’s in the same
directory as your EXE. Depending on which version of SDL_TTF you are using
it make or may not use the freetype*.dll file (or may be statically linked).
I believe more recent versions of SDL link to FreeType using the DLL
interface which means you need to have the FreeType DLL in your path or in
the folder where your EXE is.

Ken> ----- Original Message -----

From: sdl-bounces@lists.libsdl.org [mailto:sdl-bounces at lists.libsdl.org] On
Behalf Of Lars Br?mer
Sent: Saturday, November 27, 2010 6:30 AM
To: SDL Development List
Subject: Re: [SDL] SDL_ttf

yes, it is.

Is font null after the TTF_OpenFont call?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hmm, when I compile that, the box opens, I have a file and a help menue.
I can close it, but I see no text and there are reaction on mouse events or
keystrokes.

Its just a white box.

Cheers,
Lars>Best advice is to get the ShowFont sample application working. It should

work out of the box.

Hello,

I’m trying to use SDL_ttf 2.0, but I’m getting an error from TTF_GetError(). TTF_Init() is working properly. I’m using Eclipse as an IDE. The other libraries work well (SDL2_main, SLD2_image…)

Code:
Couldn’t load font file

I tried to use strace to help me, but I still can’t figure out what to do

Code:

strace -o program.log ./FGD && grep -i ttf program.log

TTF_OpenFont: Couldn’t load font file
open("/usr/lib/x86_64-linux-gnu/libSDL_ttf-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
open(“lazy.ttf”, O_RDONLY) = 3
write(1, “TTF_OpenFont: Couldn’t load font”…, 38) = 38

(here is the entire *.log http://pastebin.com/minTBJVB )

I’m using ubuntu 13.10, I downloaded some packages like libfreetype6-dev… and idk what to do anymore…
I downloaded some different fonts and I used some fonts from “/usr/share/fonts/truetype/”

regards

Idk why, but it didn’t show my original topic…

So the problem I’m facing is with SDL_ttf 2.0. The other extension SDL2_image works well as SDL2_main. I’m using Eclipse on Ubuntu 13.10. I downloaded some libraries like libfreetype6-dev, since it asks freetype 2.4.8 (idk if it is correct what I did).
The error I’m getting is:

Code:
Couldn’t load font file

The file is in the correct path. If it wasn’t it would show the name of the file and say it couldn’t OPEN. (https://github.com/cmakified/SDL2_ttf/blob/master/SDL_ttf.c#L369)

I used strace to try to figure out what was going on. I had this message with the following command:

Code:
strace -o program.log ./FGD && grep -i ttf program.log

TTF_OpenFont: Couldn’t load font file
open("/usr/lib/x86_64-linux-gnu/libSDL_ttf-2.0.so.0", O_RDONLY|O_CLOEXEC) = 3
open(“lazy.ttf”, O_RDONLY) = 3
write(1, “TTF_OpenFont: Couldn’t load font”…, 38) = 38

The full *.log can be seem here http://pastebin.com/minTBJVB
Also, the code I’m using is this one:

Code:
if( TTF_Init() == -1 )
{
return false;
}
if(!TTF_WasInit() && TTF_Init()==-1) {
printf(“TTF_Init: %s\n”, TTF_GetError());
exit(1);
}
// load font.ttf at size 16 into font
TTF_Font *font;
font = TTF_OpenFont( “lazy.ttf” , 28);
if(!font) {
printf(“TTF_OpenFont: %s\n”, TTF_GetError());
// handle error
}

PS: TTF_Init works well.

I did almost everything the same way I described above (the only exception is that I downloaded GCC) on my Arch Linux which I just installed on my other laptop. The result? It worked. I think SDL2_tff doesn’t work well on Ubuntu 13.10. Shame…

what are the dependencies to compile sdl_ttf from hg?

I am on a new install of Debian 8 Jessie

I’ve built and installed sdl2, sdl_image and now trying to make sdl_ttf I
get this error:
collect2: error: ld returned 1 exit status
Makefile:504: recipe for target ‘glfont’ failed

What packages am I missing?