Reputation: 10760
I'm looking for a way to render specifically on the alpha channels of a texture. the idea is to create a "mask" in runtime, i.e. to render a texture that will act as the alpha channels of another texture.
note: I know how to use alpha channels and color key so please don't explain about those :) what I'm looking for is a way to generate a mask dynamically in runtime, using other textures.
I prefer a solution that takes an advantage of the graphic card, and not something involving getting the pixels buffer and manipulate them in the cpu.
is that possible?
Upvotes: 3
Views: 3468
Reputation: 10760
answering myself for others who might be interested:
note: this is not ideal method, it involved with several renderings and manipulating texture pixels. but it was sufficient to my specific case and its pure SDL so good enough for me.
Upvotes: 4
Reputation: 1560
Sorry if I get this wrong, but since you said "on the alpha channel" then it isn't possible, in terms of graphics, a channel is just a subgroup of AN image, along with the rgb channel, bw channel, sound channel(for depth,etc), etc.
But what I think you want to say is put ANOTHER image on top of the original mask, and the image on top is supposed to look like its covering the image below (then ajdust-adjust the transparency and viola), thus, giving off the image of a "mask". EG: A bride wearing a veil (the bride's face is the original image while the veil is translucent. By looking, you'd think of both as just one image.
There are two ways to do this, 1 being the easiest:
Edit the image that will act as a mask and change its opacity in an image manipulation program, remember to save it in png. After doing so, render the first image to texture then render the opacity edited image afterwards.
same as the first one but don't edit the second image, instead, just edit its alpha channel in SDL2. (With this method, you can control it dynamically along with time and rendering it to a texture takes advantage of the graphics card.)
Both would give of an image of 2 photos merged, with the second one acting as a mask.
Upvotes: 2