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 > Issue with transparency while Wifi & Dual Screen 3D ok :

#162761 - roubignolo - Fri Sep 12, 2008 3:24 pm

Hi all !
During the last 2 weeks, I tried to make a funny clone of the Crackdown green orbs chasing. For the moment, I'm running 3D on both screens and WiFi is OK (it only works if two DS are linked by their adhoc wifi connexion).

I'm pretty happy because on no$, it looks not that bad. But on real hardware it's a slaughter.

Anyway...

The problem is not related directly to these specs.

I've seeked the whole Internet to get some examples of how to have transparency color in a 256colors/8bits texture.

PNG versus PCx, GL_RGB vs GL_RGBA, GL_TEXTURE_COLOR0_TRANSPARENT or not, the use of texmex...

I've tried every combinaison. It just don't work.

So if someone could please post me a quick portion of code and the details of the texture files, it would be highly appreciated.

If anyone interested in my stuff, you can download it here : http://www.filedropper.com/code3dds

You run with A, jump with B, rootate with L&R.
On launch screen, click ACCEPT to detect the other DS, then to ask it to play and then start to play. On each DS.

There is a bug on the ennemy's rotation and jump.
_________________
I code at work.

#162763 - Sausage Boy - Fri Sep 12, 2008 4:08 pm

It's quite simple if you know how to do it. First step is to get a proper image conversion. Here's how you do it with texmex.

Get an image. Make the portions you want transparent transparent. Save it in a format that has transparency, png is a good choice. Use texmex with the line
Code:
texmex -4 your_image.png


-4 tells texmex to use the 256-color mode. Surprisingly, texmex is smart enough to realize that if you give it a transparent image, it should revert to 255 colors, and use the first palette entry for transparency.

Moving on, you now need to tell the DS that the first palette entry should be used for transparency. If you use glTexImage2D (I havn't looked at your code, sorry), you'll do something like this:
Code:
glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_128, TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, (u8*)trans_tex_bin);


The only important thing is that GL_TEXTURE_COLOR0_TRANSPARENT needs to be in the texture format properties. Heh, I'm not very good at explaining stuff. I'll write a small demo if you're still having trouble. :)
_________________
"no offense, but this is the gayest game ever"

#162765 - roubignolo - Fri Sep 12, 2008 4:41 pm

I saw many of your posts and tried your texmex.

I'll try again and let you know.

Cheers,
ICODEATWORK.
_________________
I code at work.

#162878 - roubignolo - Mon Sep 15, 2008 1:24 pm

Hey Sausage Boy !

It finally works but with a PNG without transparent ico and the -7 option and using this:

Code:
   glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0,  TEXGEN_TEXCOORD  ,  (u8*)arbre1_128x128);


as you already mentionned somewhere in that forum.

But now, I can't see anymore my flat non textured quats :(

Any idea ?

Cheers,
ICODEATWORK
_________________
I code at work.

#162879 - Sausage Boy - Mon Sep 15, 2008 1:42 pm

Nice that you got it working. As you surely know, GL_RGBA is the direct-color mode, meaning it doesn't use a palette and will take more space in vram. This is not a problem if you don't have a lot of textures.

I don't know about your other problem. Try to find out exactly what code change makes the quads disappear. If you have some code, I could take a look at it.
_________________
"no offense, but this is the gayest game ever"

#162880 - roubignolo - Mon Sep 15, 2008 1:55 pm

I will double check.

For the moment I don't use so many textures. But I could in the future.

How do use the paletted texture converted with texmex.

I mean, the .dta is ok but the .pal ?

Sorry for being dumb, I was born like this ;)

Cheers and many many thanks
_________________
I code at work.

#162881 - roubignolo - Mon Sep 15, 2008 3:06 pm

this one ?

void glColorTable (uint8 format, uint32 addr)
glColorTable establishes the location of the current palette. Roughly follows glColorTableEXT. Association of palettes with named textures is left to the application.
_________________
I code at work.

#162882 - Sausage Boy - Mon Sep 15, 2008 3:15 pm

You're on the right track! I made a little example, it's a modification of the Textured Quad example from devkitPro. Everything I changed to make it use a paletted format is marked with big comments.

http://blog.dev-scene.com/gaspcubed/files/2008/09/textured_quad_palette.zip
_________________
"no offense, but this is the gayest game ever"

#162918 - roubignolo - Tue Sep 16, 2008 11:33 am

The project compiles. But The texture is fully transparent.

I use my 128x128x256 texture with texmex and its -4 option.
The two files, dta & pal, are generated and I use them the way you do in your exemple.

Your example compiles in my environment.

:(:(:(:(:(



Code:

////////////////////////
//// GLOBALS
////////////////////////


int texture[2];
uint32 paletteAddr1; //Only the 3rd one is paletted





////////////////////////
//// Function called for each frame during rendering. Put any 3D models
//// of my own where I want it to be
////////////////////////
void Placer_un_object(int type, float xx, float yy, float zz, float rotxx, float rotyy, float rotzz){


switch(type){

      case 1:
   glBindTexture(GL_TEXTURE_2D, texture[2]);

---->>   glColorTable(GL_RGB256, paletteAddr1);

   glBegin(GL_QUADS);

   glTexCoord2f(1.0f, 1.0f);
                glVertex3f(xx-1.0f, yy-8.0f,   zz+0.0f);         glTexCoord2f(1.0f, 0.0f);
                glVertex3f(xx-1.0f , yy-6.0f,   zz+0.0f);
   glTexCoord2f(0.0f, 0.0f);
                glVertex3f(xx+1.0f , yy-6.0f, zz+0.0f );
                glTexCoord2f(0.0f, 1.0f);
                glVertex3f(xx+ 1.0f ,yy -8.0f, zz+0.0f );          glTexCoord2f(1.0f, 1.0f);
                glVertex3f(xx+    0.0f, yy-8.0f,zz-1.0f);
   glTexCoord2f(1.0f, 0.0f);
                glVertex3f(xx+0.0f , yy-6.0f,   zz-1.0f);         glTexCoord2f(0.0f, 0.0f);
                glVertex3f(xx+0.0f , yy-6.0f, zz+1.0f );      
   glTexCoord2f(0.0f, 1.0f);
                glVertex3f(xx+    0.0f , yy-8.0f, zz+1.0f );
   glEnd();
   break;
case 2:
   break;
   
case 3:
   break;
   
default: ;
}





/////////////////////////////////////////   
//    TEXTURES part (into the main)
/////////////////////////////////////////
   
   sImage pcx;


   loadPCX((u8*)arbre128x128, &pcx);
   image8to16(&pcx);
   glGenTextures(1, &texture[0]);
   glBindTexture(0, texture[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);
   imageDestroy(&pcx);

   loadPCX((u8*)herbe128x128, &pcx);
   image8to16(&pcx);
   glGenTextures(2, &texture[1]);
   glBindTexture(0, texture[1]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.image.data8);
   imageDestroy(&pcx);
   


   glGenTextures(3, &texture[2]);
   glBindTexture(0, texture[2]);
---->>   glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0,  TEXGEN_TEXCOORD  | GL_TEXTURE_COLOR0_TRANSPARENT ,  (u8*)arbre1_128x128_dta);
---->>   paletteAddr1 =gluTexLoadPal( (u16*)arbre1_128x128_pal, 256, GL_RGB256 );


Any idea ?

Sorry for the inconvenience :(
_________________
I code at work.


Last edited by roubignolo on Tue Sep 16, 2008 2:09 pm; edited 3 times in total

#162924 - roubignolo - Tue Sep 16, 2008 2:06 pm

Oh ! By the way, I also noticed this strange artefact usinf texmex -7 option :

[Images not permitted - Click here to view it]

Like if the transparency "mask" was shifted.
_________________
I code at work.

#162948 - Sausage Boy - Tue Sep 16, 2008 10:07 pm

The only weird thing I can see with your code is that you're supposed to call the glGenTextures() command once. See this snippet from the Paletted Cube example:
Code:

   glGenTextures(10, textureIDS);
   
   // inital full 16 bit colour texture
   glBindTexture(0, textureIDS[0]);
   glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture_bin);
   textures[0].format = GL_RGB;
   textures[0].pal_addr = 0;   
   textures[0].size = texture_bin_size;    // size field just recorded for on-screen info
   

   // Load some 16 colour textures
   glBindTexture(0, textureIDS[1]);
   glTexImage2D(0, 0, GL_RGB16, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, (u8*)texture1_RGB16_tex_bin);
   textures[1].format = GL_RGB16;
   textures[1].pal_addr = gluTexLoadPal( (u16*)texture1_RGB16_pal_bin, 16, GL_RGB16 );
   textures[1].size = texture1_RGB16_tex_bin_size+texture1_RGB16_pal_bin_size;


   ...load more textures


But I don't think that is your problem. Try with the image files from my demo, so we can be sure that the code is the problem, and not the conversion.

And yes, that's really a strange bug you've discovered. Could you please post the image that does this, so I can try to fix it?
_________________
"no offense, but this is the gayest game ever"

#162969 - roubignolo - Wed Sep 17, 2008 3:49 pm

This is the criminal

[Images not permitted - Click here to view it]
_________________
I code at work.

#162972 - Sausage Boy - Wed Sep 17, 2008 4:21 pm

Sorry, I'll need the actual .png with the alpha channel and everything intact.
_________________
"no offense, but this is the gayest game ever"

#163035 - roubignolo - Fri Sep 19, 2008 5:22 pm

Done ! I sent it to you
_________________
I code at work.