gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Semi-transparent texture problems

#123303 - Rajveer - Tue Mar 27, 2007 4:30 am

Hi guys. I have a texture, with a section of it semi-transparent. What I do is:

-Use Photoshop to save it as a PNG (24-bit with Transparency)
-Use Sausage Boy's (excellent) TexMex tool to convert it to a texture mode 1 file (RGB32_A3)
-Load it into my game, load it into VRAM with:
glTexImage2D(0, 0, GL_RGB32_A3, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD | GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T, (u8*)road3);

The problem is when in the game, no colours are displayed i.e. it's greyscale. Even the part of the texture which has no transparency is transparent. However, the darker parts of the texture are less transparent. It seems as if the colour is being stripped and used as the alpha values...or...something! Anybody got any ideas??

P.S. I've tried with Standard PNG's in Photoshop and 24-bit with transparency.

#123345 - Sausage Boy - Tue Mar 27, 2007 2:50 pm

Hmm... I have no clue. Could you please take your code, your image and the command you use with texmex and send it to my email? I'll have a look at it.
_________________
"no offense, but this is the gayest game ever"

#123352 - Rajveer - Tue Mar 27, 2007 4:24 pm

Cheers for the offer Sausage Boy! Before I do I'll give a little update:

Alpha works, I wasn't saving the file properly (I still had an opaque background which I've deleted). The image is still greyscale however, but the parts which are not semi-transparent are not semi-transparent in the game now.

#123397 - silent_code - Tue Mar 27, 2007 10:00 pm

sounds like you only copy one "channel byte", instead of all three. also remember that the channel order is not rgba on nds (15 bit color).

i'll release a demo showing off different things (mainly shadow volumes) in "a few days" and it includes .tga loading. maybe that'll help.

happy coding!


Last edited by silent_code on Tue Mar 27, 2007 11:03 pm; edited 1 time in total

#123405 - Rajveer - Tue Mar 27, 2007 10:42 pm

When you say I only copy one channel byte, do you mean when loading the file into VRAM? If so how would I copy the rest?

I'll look forward to your demo coming out in a few days, might clear it up!

#123406 - silent_code - Tue Mar 27, 2007 10:55 pm

it very much depends on what texture format you use. and i'm talking about loading... heck i overlooked you use texmex.

in general: assuming your file is rgba, you'd read a byte (red), then another (green) and another one (blue) plus alpha and convert them to each 5 bit then recombine them to a 15bit value, when using 15/16bit textures. you could also read a whole 32bit word texel (if you can) and separate the channels.

i haven't worked with texmex, so i'm of no big help with that. i can only say that it definitely sounds like you have that problem.

ps: i can't guarantee it'll be there in "a few days", as i don't have inet at home, but i'll have it done in a reasonable time. (it's near completion already).

#123501 - Rajveer - Wed Mar 28, 2007 5:16 pm

Ok I've been reading up on some things, and realise I haven't been setting up a palette or anything. Some examples only load the texture, but in the palette cube demo (where transparent textures are used) palettes are setup for each texture. Is this also where I could be going wrong? Could somebody please explain/point me to what/why I'd use a paletted texture?

I'm sure I'm not doing anything else wrong: other people have been using the exact same method of converting a 24-bit PNG with transparency enabled with TexMex mode 1 and getting it to work...

#123531 - tepples - Wed Mar 28, 2007 9:53 pm

Rajveer wrote:
Could somebody please explain/point me to what/why I'd use a paletted texture?

Why? More detail. With 4-bit paletted textures: 262144 texels per VRAM bank. With 16-bit direct color textures: 65536 texels per VRAM bank.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#123713 - silent_code - Fri Mar 30, 2007 3:12 pm

you can get away with really good looking textures, even when only using 32 colors. using palettes helps reducing texture memory usage (as tepples already pointed out) a lot. if you cleverly palletize (is that the right word?) your images, you will hardly notice the difference between a 5bit and a 15bit texture while playing.
in order to know what colors are used by the texture, you supply the palette. then, the colors of the image (the texels) are merely (5bit) indices to (15/16bit) palette entries (plus alpha), than direct color values.
you need to use this texture mode if you want to have multiple levels of alpha. the 5bit color / 3bit alpha or vice versa modes are the only ones that have this option.

ps: i plan releasing my demo today, i'll have to check licenses first, though. (like the free filesystem and demo code snippets i use in it).

#123767 - Rajveer - Fri Mar 30, 2007 11:09 pm

Thanks guys for the replies. So as an example a 32 colour paletted texture of a green apple could have 32 shades of green in it's palette, so that the texture could only use these colours cutting down on memory whilst still giving alot of detail? I gotta learn how to use paletted textures!

Also, you said that in order to use textures with multiple alpha levels you NEED to use it as a paletted texture right? In this case I'd better start looking for paletted textures tutorials!

I look forward to your demo! :)

#123776 - silent_code - Sat Mar 31, 2007 12:39 am

DEMO: http://forum.gbadev.org/viewtopic.php?t=12873

you better get tonc. that's for gba, but you can learn a lot you'll be able to apply to nds. like palettes. :^D