SDL_CreateRGBSurface+SDL_CreateTextureFromSurface = trouble?

change f->BitsPerPixel to the number 24 then it should work just tested and it came out alright with that change

raine wrote:> When I create a text using SDL2_ttf this way, the resulting texture renders okay

Code:
surface = TTF_RenderUTF8_Blended(font, str, color);
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_RenderCopy(renderer, texture, 0, &rc);

However, when I try to render this new_texture, I get nothing on the screen

Code:
f = surface->format;
new_surface = SDL_CreateRGBSurface(0, surface->w, surface->h, f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
SDL_BlitSurface(surface, 0, new_surface, 0);
SDL_SaveBMP(new_surface, “out.bmp”);
new_texture = SDL_CreateTextureFromSurface(renderer, new_surface);
SDL_RenderCopy(renderer, new_texture, 0, &rc);

However, out.bmp file does have the text printed properly.

What is wrong here?

Not to sure I think it has to do with the mask, wish I knew a bit more about this but the problem was with the mask values and the bit order. If you really want to use 32bit image then change all the mask values to 0

new_surface = SDL_CreateRGBSurface(0, surface->w, surface->h, 32, 0, 0, 0, 0);

This sets default mask values I tested worked with Blended and Shaded text.

raine wrote:>

stevo5800 wrote:

change f->BitsPerPixel to the number 24 then it should work just tested and it came out alright with that change

Is this a bug in SDL2 then?