#153674 - Kr00pS - Thu Apr 03, 2008 8:44 pm
Hi !
I'm using OpenGL to make 2D and draw sprites, tiles but I don't know how to deal with the key color of my sprites.
I've searched but I didn't find anything that works with the DS.
Thanks for help.
#153683 - Sausage Boy - Thu Apr 03, 2008 10:08 pm
I assume you mean that you're using the DS's 3D hardware to render your stuff? Transparency depends on the texture mode you're using. If you're using direct, 16bit, RGB textures, you simply clear bit15 of a pixel to make it transparent. If you're using a paletted mode, you can set bit29 of TEXIMAGE_PARAM to make 0 transparent (see gbatek)
40004A8h - Cmd 2Ah - TEXIMAGE_PARAM - Set Texture Parameters (W)
...
29 Color 0 of 4/16/256-Color Palettes (0=Displayed, 1=Made Transparent)
Of course, there are defines in libnds for all this stuff, so you don't have to fiddle around with bits and magic numbers. You'll have to find them on your own though, I don't remember. :(
_________________
"no offense, but this is the gayest game ever"
#153686 - TwentySeven - Thu Apr 03, 2008 10:47 pm
GL_TEXTURE_COLOR0_TRANSPARENT
#153716 - Kr00pS - Fri Apr 04, 2008 12:16 pm
Okay... PCX doesn't support transparent pixels...
(OLD)
Here's the result :
[Images not permitted - Click here to view it]
The color0 is the transparent one ? My sprite is a PNG modified with GIMP (the background is transparent) and transformed into PCX to load in the NDS.
I deleted the data folder and recompiled but nothing, just a black background like in the image.
Here's the code I'm using to load a PCX texture
Code: |
sImage pcx;
//load our texture
loadPCX((u8*)texture_bin, &pcx);
image8to16(&pcx);
glGenTextures(1, &m_Texture);
glBindTexture(0, m_Texture);
glTexImage2D(0, 0, GL_RGB, texture_size , texture_size, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, pcx.image.data8);
imageDestroy(&pcx);
|
#153724 - Sausage Boy - Fri Apr 04, 2008 2:40 pm
PCX isn't really the ideal format for stuff like this. I would save my images as something that handles transparency, png for example, use a PC tool to convert it and use that on my DS. I may be a little biased, but I think my texture converter, texmex, is the best one, even if it leaks a little memory from time to time. There are other tools, the Nomad Texture Converter even comes with a fancy GUI, and hopefully less memory leaks.
_________________
"no offense, but this is the gayest game ever"
#153725 - Rajveer - Fri Apr 04, 2008 3:01 pm
I second Sausage Boy's method of saving as PNG and converting with texmex, I've been using his tool for around a year now and it works really well.
#153726 - Sausage Boy - Fri Apr 04, 2008 3:56 pm
Rajveer wrote: |
I second Sausage Boy's method of saving as PNG and converting with texmex, I've been using his tool for around a year now and it works really well. |
Wow, that's amazing to hear. Got any tips for improvements?
_________________
"no offense, but this is the gayest game ever"
#153729 - Kr00pS - Fri Apr 04, 2008 5:18 pm
Thanks for the program, I converted my .png transparent file and It gave me a .dta file.
What to do with this file ? Have you a specific makefile for this ?
Thanks for all.
#153741 - Sausage Boy - Fri Apr 04, 2008 10:41 pm
.dta is raw texture pixel data. I don't know how you included the .pcx, but you can do it the same way. If you rely on the makefile including it automatically, you'll need to add a rule for .dta. Just check the makefile, copy the section for .pcx or .bin or whatever, and change all the extensions to .dta. If you're really lazy you could also get away with renaming the .dta to .bin.
_________________
"no offense, but this is the gayest game ever"
#153744 - Kr00pS - Fri Apr 04, 2008 11:17 pm
Okay, so, I'm converting the .png and the .bmp into .dta which I rename to .bin and I place to my /data/ folder.
It compiles, it runs but the transparency doesn't work again, the background of the sprite is black.
I'm using this to load .bin texture file:
Code: |
glGenTextures(1, &m_Texture);
glBindTexture(0, m_Texture);
glTexImage2D(0, 0, GL_RGB, texture_size , texture_size, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, (u8*)texture_bin); |
Thanks for your patience. :)
#153745 - Sausage Boy - Sat Apr 05, 2008 12:13 am
Not-so-obvious error this time. Turns out libnds manually sets all the alpha bits to 1 if the GL_RGB mode is used. Use GL_RGBA, it's exactly the same to the hardware, but libnds won't touch our transparencies.
Also, GL_TEXTURE_COLOR0_TRANSPARENT isn't really necessary here, it's only used for paletted textures (4-, 16- or 256-colors).
_________________
"no offense, but this is the gayest game ever"
#153748 - Rajveer - Sat Apr 05, 2008 1:53 am
Sausage Boy wrote: |
Wow, that's amazing to hear. Got any tips for improvements? |
Not really, does everything I need it to very simply. A GUI would be nice, simply because I keep forgetting which format is which and I'm always looking at readme.txt to find out, so clicking buttons would be easier! Other than that, I can't think of anything, cheers for the great tool! :)
#153755 - Kr00pS - Sat Apr 05, 2008 9:38 am
Yeah ! It works great with:
Code: |
glTexImage2D(0, 0, GL_RGBA, texture_size , texture_size, 0, TEXGEN_TEXCOORD, (u8*)texture_bin); |
and a simple convertion of the .png with your tool. Thanks for everything.
PS: I can make a GUI for your tool if you want. :)
#153801 - Sausage Boy - Sun Apr 06, 2008 5:07 pm
Hmmm, I'm not too sure about this GUI thing everybody keeps talking about, but more ways to specify the texture format than numbers only would be nice indeed.
_________________
"no offense, but this is the gayest game ever"