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 > Setting up non-16bit textures with palettes

#106620 - Rockard - Sat Oct 21, 2006 3:02 pm

I have a lot of questions here, I'll appreciate ANY help I can get!

I have tried figuring out how to load 256color textures and using them directly for some time. The existing examples seems to rely on 16bit textures, or converting them from 256col to 16bit, so no help there.
When using a loaded pcxfile directly, and setting it up with "GL_RGB256" using the glTexImage2D command, it just turns out white, so I guess it needs a palette.

Does it make any difference memorywise, if I load a pcx or a bin-file?

There exists quite a bit of texture-options:
#define GL_RGB32_A3 1 // 32 color palette, 3 bits of alpha
#define GL_RGB4 2 // 4 color palette
#define GL_RGB16 3 // 16 color palette
#define GL_RGB256 4 // 256 color palette
#define GL_COMPRESSED 5 // compressed texture
#define GL_RGB8_A5 6 // 8 color palette, 5 bits of alpha
#define GL_RGBA 7 // 15 bit direct color, 1 bit of alpha
#define GL_RGB 8 // 15 bit direct color, alpha bit autoset to 1

How do I convert the images to formats that supports these setting?
Do I need to do it, or is a simple 8bit/16bit format all that is needed?
The compiler can load pcxfiles. Can that format handle these?

Which bin-converter do you recommend, so that I can set all these alpha-values?

I guess the "glTexLoadPal(u16 *pal, u16 count, u32 addr)" command is key for loading a palette, but I can't figure out how to use it, and how to match it to a texture(if that even is needed. Maybe only one 256col palette for all textures is possible?)

thank you very much.

#106623 - Sausage Boy - Sat Oct 21, 2006 4:16 pm

Check out the Paletted Cube demo for info about palettes. The only converter I know about is my own, it's very unfinished, but it handles raw and paletted formats, not the semi transparent ones.
_________________
"no offense, but this is the gayest game ever"

#106627 - Rockard - Sat Oct 21, 2006 4:35 pm

HAH! :D

Crappo! How could I have missed it... yummy!

Thanks!!! =)

#106644 - Sausage Boy - Sun Oct 22, 2006 12:47 am

Beware. I've found a bug in my program with paletted textures, they get moved down one row, and a garbage row is inserted. I have fixed this, and will hopefully release a new version soon.
_________________
"no offense, but this is the gayest game ever"

#106730 - Rockard - Mon Oct 23, 2006 2:24 am

uh, okey!

I tried the exampel, and converted some new textures that I added to the example... but it didn't work.. =(

In the end, I found out that the bank was simply out of memory =P.
Added bankB to textures =)

YES! Please, I'll appreciate a new version very much!!!
This converter is GOLD!

btw, with this alpha-channel stuff, is it possible to have some sort of per/pixel alpha value with any of the formats?

#106806 - Sausage Boy - Mon Oct 23, 2006 5:37 pm

Yes, it's possible. There are two per pixel semi alpha modes, oen with 8 levels of alpha and 32 colors, and one with 32 levels of alpha and 8 colors.

I'm having some problems with using these modes in my converter, I think I'm doing everything right, but the semi transparency doesn't seem to work. Anyone know anything about that?
_________________
"no offense, but this is the gayest game ever"

#106815 - Rockard - Mon Oct 23, 2006 7:08 pm

Cool!

It is weird that these featues isn't available to the regular hardware-spritesystem..

When my 3dbased sprite and tilesystem is done I will never use hardwaresprites ever again!! HAAAAWHAAAW! :D

I will try out these alphamodes and see what happends.

BTW! Have you tried out delfares converter?
http://www.dcemu.co.uk/vbulletin/showthread.php?t=31834

There is minimal documentation, so I do not know what it can do, but I suspect that it only handles GL_RGB and GL_RGBA modes.

#106834 - Sausage Boy - Mon Oct 23, 2006 9:20 pm

I released a new version, it has no bugs that I know of, except semi transparent modes acting strange.

http://www.gasp.boxgamex.net/?p=19
_________________
"no offense, but this is the gayest game ever"

#106835 - tepples - Mon Oct 23, 2006 9:27 pm

Rockard wrote:
When my 3dbased sprite and tilesystem is done I will never use hardwaresprites ever again!! HAAAAWHAAAW! :D

What will you use on the other screen? Or are you planning on using display capture, with its high VRAM use and low frame rate, to service both screens? And are you giving up GBA for good?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106836 - Sausage Boy - Mon Oct 23, 2006 9:32 pm

Often, you'll have most of the action on one screen, and maybe simple information and lesser graphics on the other. I mean, the second screen could still look just as good as it would have if you didn't use 3D on the first. It doesn't suddenly look worse. Unless, of course, you use up all your vram for textures and leave some worthless bank for the second screen.
_________________
"no offense, but this is the gayest game ever"

#106837 - Rockard - Mon Oct 23, 2006 10:40 pm

tepples,
heheh, I have never programmed for gameboy advance. =P
ds is my first consolesystem to develop on.

Anyway, I will probably save a bank for sprites and stuff for the lower screen, I guess. I just haven't thought about it yet.. =P. It will probably solve itself! =D

Sausage:
Have you tried using these:
glEnable(GL_BLEND);
glAlphaFunc(BLEND_ALPHA);

?

When using those, the textures using GL_RGB32_A3 in the paletted cube example worked and looked nice with alpha!
I put a white background in there behind the cube and the edges in the texture melted in. nice =)

Btw, who did that example? Did you? Since those binfiles must have been converted first.. using _what_ program??

What paintprogram do you use for converting images? I can't get photoshop to save the pngs as I want them when using 32color paletted images. It doesn't seems to include alpha correctly. I use "export for web", but when choosing 32 colors, the soft transparent edge I made becomes flat, with only 1 color for alpha - totally transparent. GAH!

EDIT:
okey, just tried it out with Paintshoppro also. alphachannel isn't supported when converting to palettebased format, just single color transparancy. How is it possible to convert to texture format 1 and 6 if there isn't a appropriate format to convert from? Or can texmex convert fr?n 16-bit with alpha to these textureformats? Or maybe there is another format besides png that is better suitable for the purpose?

EDIT 2:

OK! Just tried converting from 16bit alpha, it worked! :P

Remember when testing, you do not see the transparencyscales when checking against the empty black space! It only works against texture!

Here is a link to the cubeexample which I have fooled around with:
http://download.yousendit.com/19B3269D4FC14DD1

Check texture number 8.
So, I think your converter works just fine! =)

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

Hey, sweet!

You don't need to worry about what format you save in, thanks to FreeImage, texmex can handle just about anything. I use regular 32bit png's with alpha. TexMex can turn 32 bit images into paletted images easily (using functions in freeimage, heh). Just save with the highest quality settings you find. Png is lossless, does 32bit colors with 8bit alpha, all while being very small, I love it. Use that (or something equivalent) and let the conversion program handle the rest.


Edit:

hmm, are 2, 7, 10 and 11 converted with the old or new version? And what about 7 anyways, is it supposed to look like that? Is it my fault?

Great work on this demo.
_________________
"no offense, but this is the gayest game ever"

#106891 - Rockard - Tue Oct 24, 2006 3:06 pm

heheh :)

Do not worry about the other numbers, they are just experiments.
I think number seven was converted using the old version, from 16bit to 16 colors or something, I do not remember. I just uploaded it with sleepy eyes for you to look at the magical texture number nine.


Thank you VERY MUCH for your help and the great proggy!

#106895 - Sausage Boy - Tue Oct 24, 2006 3:26 pm

Thanks a lot for the testing as well.
_________________
"no offense, but this is the gayest game ever"

#106938 - Rockard - Wed Oct 25, 2006 12:03 am

Hmm, one more thing, since this is related anyway..

In an image processing program:
Anyone have any idea how to decrease the amount of colours used in a 16bit picture, WITHOUT changing the bitdepth? I just want the effect, not lesser depth.

Reason for this is that converting a 16bit colorful photo using only texmex won't look so good, I prefer some dithering. But when converting from 16bit to 32 colours in an image processing program, the image has to be flattened to 8bit, which results in loosing of the alpha values.. :(

#106940 - tepples - Wed Oct 25, 2006 12:26 am

Rockard wrote:
converting a 16bit colorful photo using only texmex won't look so good, I prefer some dithering. But when converting from 16bit to 32 colours in an image processing program, the image has to be flattened to 8bit, which results in loosing of the alpha values.. :(

Then save the alpha channel, convert to indexed, convert back to RGB, and restore the alpha channel. How to save an alpha channel depends on which paint program you prefer.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106942 - Rockard - Wed Oct 25, 2006 12:56 am

Hmm, actually, I have already tried this! =P
But, it didn't work completely to my satisfaction.. :(

When flattening a 16bit picture I have to choose a backgroundcolour where the alpha is. Lets say I choose white.

When applying the saved alphachannel, the edges get a grey tone, since it has recieved colour from the white.

Check this image: http://img110.imageshack.us/img110/408/alphaflowerga8.jpg
Left is truecolor with alpha set at a black background, right is converted using the method above.

Any suggestions? :(

#106945 - tepples - Wed Oct 25, 2006 1:08 am

Rockard wrote:
Hmm, actually, I have already tried this! =P
But, it didn't work completely to my satisfaction.. :(

When flattening a 16bit picture I have to choose a backgroundcolour where the alpha is. Lets say I choose white.

When applying the saved alphachannel, the edges get a grey tone, since it has recieved colour from the white.

This is a side effect of non-premultiplied alpha.

Can you draw directly on the alpha channel? Try setting alpha to maximum (completely opaque) before using "flatten".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106959 - Sausage Boy - Wed Oct 25, 2006 7:22 am

Perhaps I should add a way to use the alpha channel from another image? That way, you can convert and dither it to your likings in your editor, save it, and use the two files to get all the alpha.
_________________
"no offense, but this is the gayest game ever"

#107001 - Rockard - Wed Oct 25, 2006 5:03 pm

tepples wrote:

This is a side effect of non-premultiplied alpha.

Can you draw directly on the alpha channel? Try setting alpha to maximum (completely opaque) before using "flatten".


Hmmm? When you convert to 8bit (thats when flatten happens automaticly), layers and alphachannels isn't possible. That is why I have to have a real backgroundcolor.. =/

Sausage Boy wrote:

Perhaps I should add a way to use the alpha channel from another image? That way, you can convert and dither it to your likings in your editor, save it, and use the two files to get all the alpha.


Hmm, I do not think it will make any difference, since the image will already be "destroyed" when converting it to 32 colors in the imageprogram.. applying the alpha afterwards is what I already tried out. =/

I think the dodgy solution I have to try is to so simply paste the converted image over the 16bit alpha one, but only covering the area that doesn't have any alpha. It's usually just the edges anyway that have alpha..
But its so DODGY :(. I have loads of images I need to convert for my game!

Hmm, there exists a freeware open-source photoshop-type program I think. Anyone know the name? Maybe I can suggest the feature, if it doesn't exist already..

#107009 - Sausage Boy - Wed Oct 25, 2006 5:43 pm

Are you thinking of The Gimp?

I mean that you convert your image to 32 colors, but you save the regular unconverted image, and use the alpha values from there and the pixel values from the dithered image. Not a very good solution, but I think it would work.
_________________
"no offense, but this is the gayest game ever"

#107023 - Rockard - Wed Oct 25, 2006 7:47 pm

OH! :S

I totally forgot that you can convert the image to 32 colors, and discard the alphachanges! HAaah!

Actually, I now think that I maybe can do a macro in ps that does all the stuff =).

I now need to find an option that removes ALL transparencys, so that all colors, even if they hardly is seen, is totally maxed up. Converting to 8bit without transparency takes notice if the transparency level isn't high enough, and then discards the color - which makes the image bad for processing the alpha on.

http://img281.imageshack.us/img281/2812/alphaflower2pl5.jpg

Left image, converted as you suggested, without using the alpha.
As you can see, the lightest areas on the leaf are cut out.

Right image: converted with transparencys intact. You can see that there is faint colors left on the leaf.

What I need is an image, where the alphavalues are simply removed, so that as much colour as possible on the leaf is left intact. then, I can apply the alphavalues again!

Arghh, this gets complicated :P

Sausage Boy, can you possibly make a converter, that quite simply reads the 16bit alpha image and removes all alpha values, (since photoshop doesn't do it the accurate way) and saves it?

That would be what is needed. Then, it is possible to convert the quite weird looking image (I guess the edges will have a very strong colors now, esspecially the end of that leaf) to 32 colors, and apply the alpha values again.

VIOLA! :D

#107024 - Sausage Boy - Wed Oct 25, 2006 7:52 pm

hmmm, Photoshop want's to be smart... :P

A nice solution I came up with would be a transparency stripper as you suggested, but it saves the transparency to a seperate file, and then you can use the transparency it saved with your dithered image. Sounds good?
_________________
"no offense, but this is the gayest game ever"

#107026 - Rockard - Wed Oct 25, 2006 8:14 pm

EDIT! I got it wrong.

YES! This sounds good! So. I input the file, and out comes two files, one with the alpha, and one with the image stripped of the alpha?

That would be the ultimate solution! =)

#107029 - Sausage Boy - Wed Oct 25, 2006 8:35 pm

I'll get to work on that, expect a new release in a couple of days. Thanks for your input :D. This stuff is more complicated than I thought.
_________________
"no offense, but this is the gayest game ever"

#107031 - Rockard - Wed Oct 25, 2006 8:54 pm

Totally marvelous! =)

Now I can take a "break" to do some schoolwork, for once... heh :P

#108032 - Sausage Boy - Sat Nov 04, 2006 4:46 pm

New version with the promised features.
http://www.gasp.boxgamex.net/?p=21

Strip alpha with
TexMex image.png -m alphastrip
-m changes the mode to alphastrip

Use it with
TexMex image.png -alpha image_alpha.png -1
-alpha sets the image to use for alpha.
_________________
"no offense, but this is the gayest game ever"

#121002 - themadcelt - Thu Mar 08, 2007 1:00 am

Sausage Boy - your link appears to have been eaten by the interweb. Is there any chance I can still get a copy of your program? I've been searching everywhere for an A3/A5 image conversion app. If I can't find one, I'll have to make my own and no one wants that to happen.

#121139 - Rockard - Fri Mar 09, 2007 12:20 pm

Until he fixes his site: http://download.yousendit.com/16B860DC3558C082

=)) great prog.

#121154 - themadcelt - Fri Mar 09, 2007 4:16 pm

Thanks Rockard - SausageBoy was kind enough to send me an email with the program.