[SDL] SDL 1.3 and SDL_ttf
Sam Lantinga
slouken at libsdl.org
Wed Jul 21 18:41:36 PDT 2010
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 at libsdl.org> 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
>> >>>> <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
>
>
> _______________________________________________
> 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
More information about the SDL
mailing list