So what I am trying to do is manually color key a SDL_Texture. This is born out of the fact that I want to create an SDL_Texture from an SDL_Surface, but SDL_CreateTextureFromSurface() does not return a streamable texture.
So I
-load a surface and convert it to the display format
-create a streaming texture in the display format
-lock the texture to access its pixels
-memcpy the surface pixels to the texture pixels
-map the color key and the transparent pixel in the display format
-go through the texture pixels and substitute all the color key pixels with transparent pixels
-unlock the surface
So I can find the color key pixels and replace them with another color just fine. The problem is that I can’t seem to make the color transparent even though I am mapping the alpha to 0.
Here’s my code:
Code:
//The final texture
SDL_Texture* newTexture = NULL;
Could it have to do with the display format not supporting alpha? I tried making everything SDL_PIXELFORMAT_RGBA4444, but that didn’t work either.------------------------
SDL 2.0 Tutorial (http://lazyfoo.net/tutorials/SDL/index.php) now under construction!
Of course a 32bit RGBA format would be SDL_PIXELFORMAT_RGBA8888 not SDL_PIXELFORMAT_RGBA4444. 3 semester of calculus, linear algebra, 2 semesters of physics and still I screw up 2nd grade math. [Embarassed]------------------------
SDL 2.0 Tutorial (http://lazyfoo.net/tutorials/SDL/index.php) now under construction!
Also check out SDL_ConvertColorkeyToAlpha() in SDL_surface.cOn Mon, Aug 19, 2013 at 9:45 PM, Lazy Foo’ wrote:
**
…well I feel stupid.
Of course a 32bit RGBA format would be SDL_PIXELFORMAT_RGBA8888 not
SDL_PIXELFORMAT_RGBA4444. 3 semester of calculus, linear algebra, 2
semesters of physics and still I screw up 2nd grade math. [image:
Embarassed]
Hello,
maybe it’s not the best first post but i now develop applications with SDL2, very nice work and touch screen support is very cool!
I tried the lazyfoo tutorial that is very nice too.
But on the tutorial 40 I tried the code and transparency doesn’t work.
If I change the background color it still stays white for the supposed transparent pixels…
Could you please help me? I’m trying to convert my SDL 1.2 perl app in SDL 2.05 c++ app.
Thanks and have nice holidays.