Color keying with PVR

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
AntiPasta
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Thu Feb 03, 2005 1:59 pm
Has thanked: 0
Been thanked: 0
Contact:

Color keying with PVR

Post by AntiPasta »

Hi,

first off, I'm new on this board, and I'm also pretty new with coding on the DC (having moved in from low-level PSX coding). I hope to have a pleasant stay here :-)

Right now I'm coding a simple "bouncing sprite" thingie with KOS. Because I couldn't get the Linux dev environment to work, I'm using some sort of integrated package using Dev-C++ that I found somewhere, it comes with KOS 1.2.0. After wading thru the absence of documentation on the PowerVR functions, I finally succeeded in displaying a background in the OP "layer" and a sprite on top of that in the TR "layer". Basically what I'm trying to do is define a specific colour in the sprite as "see-through", i.e. 100% transparent. My sprite is in PNG format, and I'm using png_to_texture() to load it. Now what would be the best way to implement this?
Thanks in advance!
I am not really from outer space.
User avatar
toastman
Iron Fist of Justice
Iron Fist of Justice
Posts: 4933
Joined: Sat Nov 10, 2001 3:08 am
Location: New Orleans
Has thanked: 0
Been thanked: 0
Contact:

Post by toastman »

PNGs support transparency, what you are attempting is to mimic core functionality of the file format.
Could you post the image and the relevant code? Maybe I'm not understanding.
No signature.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am
Has thanked: 0
Been thanked: 1 time

Post by BlackAura »

The best way is to get an image editor that can handle alpha channels, use those for transparency. Basically, you create an alpha channel where transparent pixels have an alpha value of 0 (black), and opaque pixels have an alpha value of 255 (white). You can also use intermediate values for varying levels of transparency - 128 is 50% transparent, for example.

Once you've done that, you need to render the image using the transparent display list. It should automatically have transparencies.
AntiPasta
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Thu Feb 03, 2005 1:59 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by AntiPasta »

toastman wrote:PNGs support transparency, what you are attempting is to mimic core functionality of the file format.
Well, I'm not really trying to mimic it, I'm just looking for "boolean" transparency. But I'll fiddle around with the PNG some more, I havent got it to work yet though.
I am not really from outer space.
User avatar
GyroVorbis
Elysian Shadows Developer
Elysian Shadows Developer
Posts: 1874
Joined: Mon Mar 22, 2004 4:55 pm
Location: #%^&*!!!11one Super Sonic
Has thanked: 81 times
Been thanked: 64 times
Contact:

Post by GyroVorbis »

BlackAura wrote:The best way is to get an image editor that can handle alpha channels, use those for transparency. Basically, you create an alpha channel where transparent pixels have an alpha value of 0 (black), and opaque pixels have an alpha value of 255 (white). You can also use intermediate values for varying levels of transparency - 128 is 50% transparent, for example.

Once you've done that, you need to render the image using the transparent display list. It should automatically have transparencies.
What BA suggests here is DEFINATELY the way to go.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Post by OneThirty8 »

AntiPasta wrote:
toastman wrote:PNGs support transparency, what you are attempting is to mimic core functionality of the file format.
Well, I'm not really trying to mimic it, I'm just looking for "boolean" transparency. But I'll fiddle around with the PNG some more, I havent got it to work yet though.
It shouldn't be that hard to do with raw pixel data if I undertand things properly. If you can steal some of the PNG code and modify it so after you load the pixel data into a buffer, you can manipulate it a bit before loading it into texture memory, you could set the alpha channel based on the R, G, and B values - if it's a given color, make that pixel transparent. Otherwise, set it to fully opaque.

Or, just do what BlackAura said and save yourself the trouble. I think the GIMP will do the job if you need something that's both good and free.
AntiPasta
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Thu Feb 03, 2005 1:59 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by AntiPasta »

OK thanks once more, I tried the GIMP but for some reason the area I want to be transparent is white instead and the rest of the picture has only the Red channel it seems... how exactly do I go about in GIMP? All I want is to set RGB(0,0,0) to 100% transparent.
I am not really from outer space.
quarn
DC Developer
DC Developer
Posts: 80
Joined: Wed Oct 17, 2001 7:44 pm
Location: Sweden
Has thanked: 0
Been thanked: 1 time

Post by quarn »

AntiPasta wrote:OK thanks once more, I tried the GIMP but for some reason the area I want to be transparent is white instead and the rest of the picture has only the Red channel it seems... how exactly do I go about in GIMP? All I want is to set RGB(0,0,0) to 100% transparent.
1) Open the GIMP.
2) Open your picture.
3) Right click on the picture and choose "Picture -> alpha -> add alpha channel" (if possible)
4) Right click on the picture and choose "Select -> by color"
5) left click the color you want selected
6) Right click on the picture and choose "Edit -> empty" or press CTRL+K. A black and gray chessboard pattern should appear where your selected color used to be.
7) Done
AntiPasta
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Thu Feb 03, 2005 1:59 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by AntiPasta »

Thanks, that's exactly what I needed to know :-)
At first it still didnt work (sprite is in all red with a light blue background) but I hazarded a guess and chanced the pvr_poly_cxt_txr() argument to PVR_TXRFMT_ARGB1555 (it was RGB565) and now the background is gone - but the sprite was still displayed with messed up colours. After some more messing around I got it to work fine when using PVR_TXRFMT_ARGB4444 :mrgreen:
Is this really required btw? Is there a way to have the PNG loaded to RGB1555 instead of 4444 to keep more colourspace available to the primary colours?
I am not really from outer space.
quarn
DC Developer
DC Developer
Posts: 80
Joined: Wed Oct 17, 2001 7:44 pm
Location: Sweden
Has thanked: 0
Been thanked: 1 time

Post by quarn »

Yes, you load it with specifiying "PNG_MASK_ALPHA". For example:

png_to_texture("texture.png", textureaddr, PNG_MASK_ALPHA);

and then you specify ARGB1555 as texturemode
AntiPasta
DCEmu Fast Newbie
DCEmu Fast Newbie
Posts: 20
Joined: Thu Feb 03, 2005 1:59 pm
Has thanked: 0
Been thanked: 0
Contact:

Post by AntiPasta »

Great! Thanks, I'll shut up now :mrgreen:
I am not really from outer space.
Post Reply