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 > How to do transparency in non-16bit/alpha textures?

#106875 - Extreme Coder - Tue Oct 24, 2006 10:09 am

Hey guys.
I've recently began the framework for a 3D game I'm working on(see www.extremecoder.co.nr), and there are a few questions that I have:
What is the best/right way to do transparency on textures that aren't 16-bit(like the ones in the examples)?
Is it possible to have transparency+alpha(or blending) in the same texture?
If so, how?
Oh, and why are textures always rotated 90 degrees to the right?

Thanks.


Last edited by Extreme Coder on Tue Oct 24, 2006 12:55 pm; edited 1 time in total

#106883 - Rockard - Tue Oct 24, 2006 12:34 pm

Check my topic "Setting up non-16bit textures with palettes" a few threads down, and you will find a good tool for that.

#106884 - Extreme Coder - Tue Oct 24, 2006 12:53 pm

I'm not asking for which tool to use, because that I know already. I am asking, which code needs to be added to support the things requested above?

#106888 - Sausage Boy - Tue Oct 24, 2006 2:41 pm

Texture modes 1 and 6 support alpha transparency (GL_RGB32_A3 and GL_RGB8_A5 in libnds). Treat them as standard paletted textures, there is tons of code in the paletted cube demo. Note that the alpha only works against another texture.
_________________
"no offense, but this is the gayest game ever"

#106905 - Extreme Coder - Tue Oct 24, 2006 5:18 pm

Sausage Boy: But how transparent would the texture be? Would it be 25% or 50% or xx% transparent? And how can that be controlled?
When converting an image to a paletted texture using your converter, what color in the image would become completely transparent? and what code should I add to support this one-color transparency?

Thanks again in advance,
Extreme Coder

#106908 - Sausage Boy - Tue Oct 24, 2006 6:09 pm

The mode GL_RGB32_A3 means you get 32 colors and 3 bits of alpha, so that makes 8 different levels of transparency. GL_RGB8_A5 is the other way around, that is, 32 levels of alpha.

My converter doesn't use a color for transparency, it uses the alpha layer in the image. I find the idea of a tranparent color awful, I mean, tools support alpha layers, it makes more sense, so why complicate things more than needed?
_________________
"no offense, but this is the gayest game ever"

#106909 - Rockard - Tue Oct 24, 2006 6:18 pm

You do not add code to make an image transparent. That is included in the picture.

The per-pixel transparency levels is saved with the bin!
Create the transparent picture in a paintprogram like photoshop. Save as png-24 (palette-based png like 8bit-pictures and lower do not support per pixel transparency with different levels of transparancy. All 8bit and lower only supports one color which is set to 100% transparent). Then you use texmex to convert the png24 image to a suitable format, like texture mode 1 or 6 as suggested. The output is a bin with information about the transparency included. Input in your source, and add glEnable(GL_BLEND); and glAlphaFunc(BLEND_ALPHA);
or else the images won't blend. That's all! =D

Btw, your webpage doesn't work!

edit: whups, sausage got first..

#106934 - Extreme Coder - Tue Oct 24, 2006 11:14 pm

About my site, it's gone down for about a few days without me noticing. It will probably come back later(or I will move to another host:P)
Looks like either me or you got transparencies, blending and alpha all mixed up :)

And Sausage Boy: Then how would I make the area around a sprite(which is not used or empty) not get drawn? This part is what I call transparency:)
And how do I change the alpha bits?

#106958 - Sausage Boy - Wed Oct 25, 2006 7:18 am

Make your source image file transparent. Every mode submits fully transparent pixels, just make them transparent in you image editor. If TexMex detects an image with transparent pixels, and converts to a regular paletted type (GL_RGB4, GL_RGB16 or GL_RGB256), it automagially converts your image into numberofcolors-1 colors, and assigns every transparent pixel to color 0. It is actually possible to choose if you want palette index 0 to be transparent, so if texmex doesn't find any transparent pixels, it uses the entire numberofcolors for colors.
_________________
"no offense, but this is the gayest game ever"

#106981 - Extreme Coder - Wed Oct 25, 2006 12:56 pm

Thanks Sausage Boy. But that means I won't have to add anything to my code, just the procedures above? :) And does that also mean that I can't get the transparency I'm talking about with paletted alpha modes?
Sorry for the long list of questions, and thanks again.

#106986 - Sausage Boy - Wed Oct 25, 2006 1:48 pm

You are talking about regular fully see-through pixels, right? In that case, it's perfectly possible in every mode (except 16 bit raw I think).
_________________
"no offense, but this is the gayest game ever"

#107011 - Extreme Coder - Wed Oct 25, 2006 5:57 pm

Yup I was talking about these. Thanks Sausage Boy! I will be trying out what I found out in this thread later today.

#120572 - Tantrum - Sun Mar 04, 2007 7:15 pm

Sausage Boy wrote:
It is actually possible to choose if you want palette index 0 to be transparent


I just wanted to add an actual code snippet of doing this into the thread. I was searching and didn't find it explicitly stated and had to go hunting. Added to save someone else hunting :)

The define GL_TEXTURE_COLOR0_TRANSPARENT is what you need, used like,

glTexImage2D(0, 0, GL_RGB16, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, (u8*)someBitmap);

#120575 - gabebear - Sun Mar 04, 2007 8:03 pm

just to clarify, GL_RGB16 is for 16color textures and you can do alpha on 16bit textures by setting the last bit in GL_RGBA mode. The DS uses 5bits per channel for rgb and the last bit is alpha for textures; the GL_RGB mode sets this bit on every pixel for you.

By setting GL_TEXTURE_COLOR0_TRANSPARENT you are making color 0 in every texture mode to clear.