SDL 1.3 and SDL_ttf

I think this was answered before - I searched the forum but can’t find a
definitive answer.
I downloaded the latest packaged source-code for SDL_ttf, and did this:
./configure --with-sdl-prefix=$HOME/.SDL --prefix=$HOME/.SDL
make && make install
I have SDL 1.3 install in ~/.SDL
This builds fine with no errors. Then, when I compile my program, none of
the text displays. Everything initializes fine with no issues or errors,
but I can’t see my text. Here is my code to print:
void printxy( char *text, int x, int y, Uint8 r, Uint8 g, Uint8 b ) {
if( !font ) { printf( “No font to print!\n” ); return; } // Can’t
print without font
if( !text ) { printf( “No text to print!\n” ); return; } // Can’t
print without text
SDL_Color c;
SDL_Rect rt;
c.r = r; c.g = g; c.b = b;
SDL_Surface *surface = TTF_RenderText_Solid( font, (const char *)text, c
);
SDL_Texture *texture = SDL_CreateTextureFromSurface( 0, surface );
rt.x = x; rt.y = y; rt.w = surface->w; rt.h = surface->h;
//SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
SDL_RenderCopy( texture, NULL, NULL );
SDL_DestroyTexture( texture );
SDL_FreeSurface( surface );

}
font is a global variable that has been set properly. I don’t get segfaults
or anything! It just doesn’t print.

Any suggestions?
-Alex

SDL_RenderUpdate();?------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-AlexOn Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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

I did a lot of googling, and it appears as though SDL_ttf, in it’s current
state, does not work with SDL 1.3? Can anyone confirm?On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <@Alex_Barry> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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

Just for fun, I’ve kept at this, and did some sanity checks - looks like the
surface isn’t being converted properly to a texture, with this error:
"Compatible pixel format cannot be found"
Have I gone completely insane?On Sun, Jul 18, 2010 at 9:58 PM, Alex Barry <@Alex_Barry> wrote:

I did a lot of googling, and it appears as though SDL_ttf, in it’s current
state, does not work with SDL 1.3? Can anyone confirm?

On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <@Alex_Barry> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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

A lot of tinkering later, and I go into the source of SDL_ttf, and see that
the surface pixel format is a palette. Long story short, I fixed my
function, and now it looks like this:

void printxy( char *text, int x, int y, Uint8 r, Uint8 g, Uint8 b ) {
if( !font ) { printf( “No font to print!\n” ); return; } // Can’t
print without font
if( !text ) { printf( “No text to print!\n” ); return; } // Can’t
print without text
SDL_Color c;
SDL_Rect rt;
c.r = r; c.g = g; c.b = b;

SDL_Surface *surface = TTF_RenderText_Solid( font, (const char *)text, c

);
if( surface == NULL ) {
printf( “Couldn’t even make the surface! WTF: %s\n”, TTF_GetError()
);
}
SDL_Surface *recast = SDL_CreateRGBSurface( 0, surface->w, surface->h,
24, 0, 0, 0, 0 ); // <— This is the fix!
SDL_BlitSurface( surface, NULL, recast, NULL ); // <-- Blit Surface will
automatically convert the original 8-bit image to a 24 bit image.

SDL_Texture *texture = SDL_CreateTextureFromSurface( 0, recast );
if( texture == NULL ) {
    printf( "Couldn't even make the texture!  WTF: %s\n", TTF_GetError()

);
}
rt.x = x; rt.y = y; rt.w = surface->w; rt.h = surface->h;
SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
SDL_RenderCopy( texture, NULL, (const SDL_Rect *)&rt );
SDL_DestroyTexture( texture );
SDL_FreeSurface( recast );
SDL_FreeSurface( surface );

}

I hope that helps someone,
-AlexOn Sun, Jul 18, 2010 at 10:19 PM, Alex Barry <@Alex_Barry> wrote:

Just for fun, I’ve kept at this, and did some sanity checks - looks like
the surface isn’t being converted properly to a texture, with this error:
"Compatible pixel format cannot be found"
Have I gone completely insane?

On Sun, Jul 18, 2010 at 9:58 PM, Alex Barry <@Alex_Barry> wrote:

I did a lot of googling, and it appears as though SDL_ttf, in it’s current
state, does not work with SDL 1.3? Can anyone confirm?

On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <@Alex_Barry> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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

I’m glad you figured it out. Thanks!On Sun, Jul 18, 2010 at 7:32 PM, Alex Barry <alex.barry at gmail.com> wrote:

A lot of tinkering later, and I go into the source of SDL_ttf, and see that
the surface pixel format is a palette.? Long story short, I fixed my
function, and now it looks like this:

void printxy( char *text, int x, int y, Uint8 r, Uint8 g, Uint8 b ) {
??? if( !font ) { printf( “No font to print!\n” ); return; }??? // Can’t
print without font
??? if( !text ) { printf( “No text to print!\n” ); return; }??? // Can’t
print without text
??? SDL_Color c;
??? SDL_Rect rt;
??? c.r = r; c.g = g; c.b = b;

??? SDL_Surface *surface = TTF_RenderText_Solid( font, (const char *)text, c
);
??? if( surface == NULL ) {
??? ??? printf( “Couldn’t even make the surface!? WTF: %s\n”, TTF_GetError()
);
??? }
??? SDL_Surface *recast = SDL_CreateRGBSurface( 0, surface->w, surface->h,
24, 0, 0, 0, 0 ); // <— This is the fix!
??? SDL_BlitSurface( surface, NULL, recast, NULL ); // <-- Blit Surface will
automatically convert the original 8-bit image to a 24 bit image.

??? SDL_Texture *texture = SDL_CreateTextureFromSurface( 0, recast );
??? if( texture == NULL ) {
??? ??? printf( “Couldn’t even make the texture!? WTF: %s\n”, TTF_GetError()
);
??? }
??? rt.x = x; rt.y = y; rt.w = surface->w; rt.h = surface->h;
??? SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
??? SDL_RenderCopy( texture, NULL, (const SDL_Rect *)&rt );
??? SDL_DestroyTexture( texture );
??? SDL_FreeSurface( recast );
??? SDL_FreeSurface( surface );

}

I hope that helps someone,
-Alex

On Sun, Jul 18, 2010 at 10:19 PM, Alex Barry <alex.barry at gmail.com> wrote:

Just for fun, I’ve kept at this, and did some sanity checks - looks like
the surface isn’t being converted properly to a texture, with this error:
"Compatible pixel format cannot be found"
Have I gone completely insane?

On Sun, Jul 18, 2010 at 9:58 PM, Alex Barry <alex.barry at gmail.com> wrote:

I did a lot of googling, and it appears as though SDL_ttf, in it’s
current state, does not work with SDL 1.3?? Can anyone confirm?

On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <alex.barry at gmail.com> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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


? ? -Sam Lantinga, Founder and President, Galaxy Gameworks LLC

Any chance of making SDL_CreateTextureFromSurface() bump up the format from
SDL_Surface() if it’s palette mode? That would probably save a lot of
people a lot of hassle.
Also, I was passing a NULL texture to SDL_RenderCopy(), and it wasn’t
causing in error. As much as I’d prefer no errors, it might be good to get
rid of error checking in there, and allowing the program to segfault…then
again, keeping a program running is good, and I suppose it’s the
programmer’s job to do error checks.
Thoughts?

-AlexOn Tue, Jul 20, 2010 at 4:04 AM, Sam Lantinga wrote:

I’m glad you figured it out. Thanks!

On Sun, Jul 18, 2010 at 7:32 PM, Alex Barry <@Alex_Barry> wrote:

A lot of tinkering later, and I go into the source of SDL_ttf, and see
that
the surface pixel format is a palette. Long story short, I fixed my
function, and now it looks like this:

void printxy( char *text, int x, int y, Uint8 r, Uint8 g, Uint8 b ) {
if( !font ) { printf( “No font to print!\n” ); return; } // Can’t
print without font
if( !text ) { printf( “No text to print!\n” ); return; } // Can’t
print without text
SDL_Color c;
SDL_Rect rt;
c.r = r; c.g = g; c.b = b;

SDL_Surface *surface = TTF_RenderText_Solid( font, (const char

*)text, c

);
if( surface == NULL ) {
printf( “Couldn’t even make the surface! WTF: %s\n”,
TTF_GetError()
);
}
SDL_Surface *recast = SDL_CreateRGBSurface( 0, surface->w,
surface->h,
24, 0, 0, 0, 0 ); // <— This is the fix!
SDL_BlitSurface( surface, NULL, recast, NULL ); // <-- Blit Surface
will
automatically convert the original 8-bit image to a 24 bit image.

SDL_Texture *texture = SDL_CreateTextureFromSurface( 0, recast );
if( texture == NULL ) {
    printf( "Couldn't even make the texture!  WTF: %s\n",

TTF_GetError()

);
}
rt.x = x; rt.y = y; rt.w = surface->w; rt.h = surface->h;
SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
SDL_RenderCopy( texture, NULL, (const SDL_Rect *)&rt );
SDL_DestroyTexture( texture );
SDL_FreeSurface( recast );
SDL_FreeSurface( surface );

}

I hope that helps someone,
-Alex

On Sun, Jul 18, 2010 at 10:19 PM, Alex Barry <@Alex_Barry> wrote:

Just for fun, I’ve kept at this, and did some sanity checks - looks like
the surface isn’t being converted properly to a texture, with this
error:

"Compatible pixel format cannot be found"
Have I gone completely insane?

On Sun, Jul 18, 2010 at 9:58 PM, Alex Barry <@Alex_Barry> wrote:

I did a lot of googling, and it appears as though SDL_ttf, in it’s
current state, does not work with SDL 1.3? Can anyone confirm?

On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <@Alex_Barry> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code (i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries < nfries88 at yahoo.com> wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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


-Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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

Programmers error check failed input | Compilers error check failed
programming

We aren’t building a compiler?

Of course, there always the preprocessor. Which could be useful, for
catching really obvious goofs. Sounds like a low priority.
Maybe it would have potential use in some kind of SDL 1.3 RAD environment.

Sometimes such errors are useful for letting the programmer know
he/she is starting to fall asleep.On Tue, Jul 20, 2010 at 9:35 AM, Alex Barry <alex.barry at gmail.com> wrote:

Also, I was passing a NULL texture to SDL_RenderCopy(), and it wasn’t
causing in error.? As much as I’d prefer no errors, it might be good to get
rid of error checking in there, and allowing the program to segfault…then
again, keeping a program running is good, and I suppose it’s the
programmer’s job to do error checks.
Thoughts?

-Alex

Also, I was passing a NULL texture to SDL_RenderCopy(), and it wasn’t
causing in error. As much as I’d prefer no errors, it might be good to get
rid of error checking in there, and allowing the program to segfault…then
again, keeping a program running is good, and I suppose it’s the
programmer’s job to do error checks.
Thoughts?

-Alex

Programmers error check failed input | Compilers error check failed
programming

We aren’t building a compiler?

This is the sort of thing I’d protect with an assertion. If the reference is
NULL,
raise an exception. Of course, you can’t really do that in C, so… shrug>----- Original Message ----

From: Jeremiah
Subject: Re: [SDL] SDL 1.3 and SDL_ttf
On Tue, Jul 20, 2010 at 9:35 AM, Alex Barry <alex.barry at gmail.com> wrote:

Yes, I plan to do that at some point. Patches welcome! :)On Tue, Jul 20, 2010 at 6:35 AM, Alex Barry <alex.barry at gmail.com> wrote:

Any chance of making SDL_CreateTextureFromSurface() bump up the format from
SDL_Surface() if it’s palette mode?? That would probably save a lot of
people a lot of hassle.
Also, I was passing a NULL texture to SDL_RenderCopy(), and it wasn’t
causing in error.? As much as I’d prefer no errors, it might be good to get
rid of error checking in there, and allowing the program to segfault…then
again, keeping a program running is good, and I suppose it’s the
programmer’s job to do error checks.
Thoughts?

-Alex

On Tue, Jul 20, 2010 at 4:04 AM, Sam Lantinga <@slouken> wrote:

I’m glad you figured it out. ?Thanks!

On Sun, Jul 18, 2010 at 7:32 PM, Alex Barry <alex.barry at gmail.com> wrote:

A lot of tinkering later, and I go into the source of SDL_ttf, and see
that
the surface pixel format is a palette.? Long story short, I fixed my
function, and now it looks like this:

void printxy( char *text, int x, int y, Uint8 r, Uint8 g, Uint8 b ) {
??? if( !font ) { printf( “No font to print!\n” ); return; }??? // Can’t
print without font
??? if( !text ) { printf( “No text to print!\n” ); return; }??? // Can’t
print without text
??? SDL_Color c;
??? SDL_Rect rt;
??? c.r = r; c.g = g; c.b = b;

??? SDL_Surface *surface = TTF_RenderText_Solid( font, (const char
*)text, c
);
??? if( surface == NULL ) {
??? ??? printf( “Couldn’t even make the surface!? WTF: %s\n”,
TTF_GetError()
);
??? }
??? SDL_Surface *recast = SDL_CreateRGBSurface( 0, surface->w,
surface->h,
24, 0, 0, 0, 0 ); // <— This is the fix!
??? SDL_BlitSurface( surface, NULL, recast, NULL ); // <-- Blit Surface
will
automatically convert the original 8-bit image to a 24 bit image.

??? SDL_Texture *texture = SDL_CreateTextureFromSurface( 0, recast );
??? if( texture == NULL ) {
??? ??? printf( “Couldn’t even make the texture!? WTF: %s\n”,
TTF_GetError()
);
??? }
??? rt.x = x; rt.y = y; rt.w = surface->w; rt.h = surface->h;
??? SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
??? SDL_RenderCopy( texture, NULL, (const SDL_Rect *)&rt );
??? SDL_DestroyTexture( texture );
??? SDL_FreeSurface( recast );
??? SDL_FreeSurface( surface );

}

I hope that helps someone,
-Alex

On Sun, Jul 18, 2010 at 10:19 PM, Alex Barry <alex.barry at gmail.com> wrote:

Just for fun, I’ve kept at this, and did some sanity checks - looks
like
the surface isn’t being converted properly to a texture, with this
error:
"Compatible pixel format cannot be found"
Have I gone completely insane?

On Sun, Jul 18, 2010 at 9:58 PM, Alex Barry <alex.barry at gmail.com> wrote:

I did a lot of googling, and it appears as though SDL_ttf, in it’s
current state, does not work with SDL 1.3?? Can anyone confirm?

On Sun, Jul 18, 2010 at 5:49 PM, Alex Barry <alex.barry at gmail.com> wrote:

Nothing that simple - I have SDL_RenderPresent(); later in the code
(i
presume you meant that…SDL_RenderUpdate() doesn’t seem to exist)
I have other things being displayed without issue

-Alex

On Sun, Jul 18, 2010 at 5:32 PM, Nathaniel J Fries wrote:

SDL_RenderUpdate();?


EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/


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


? ? -Sam Lantinga, Founder and President, Galaxy Gameworks LLC


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


? ? -Sam Lantinga, Founder and President, Galaxy Gameworks LLC