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 > Some problem with PCX and Transparency

#151397 - Satan2k - Mon Feb 25, 2008 7:58 am

Hello everyone,

I got alittle problem with the transparency when i draw a pcx on a GL_QUAD. I don't know why it is not working. I did everything right (i think)

First, I get my PCX to 8 bit (256 colors), then i modified the index 0 on the palette which is the transparency. And when i use

Code:

glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, pcx.image.data8);


it is just not working. My surface is rendered, but the alpha color is still visible. Any suggestions?

Thanks in advance,

#151398 - Satan2k - Mon Feb 25, 2008 8:14 am

After spending all night to fix it, i found the solution in the header file


image8to16trans(&pcx,0);

I can say now, i been owned :p. Post to close, sorry for the inconvenience

#175576 - SchmendrickSchmuck - Fri Dec 31, 2010 12:28 am

I hate to be bumping a nearly three year old topic, but I'm having this exact same problem, and I couldn't find any more recent topics covering this issue.

My pcx loading code:

Code:

   sImage pcx;

   loadPCX((u8*)tex, &pcx);
   
   image8to16trans(&pcx, transCol);

   glGenTextures(1, &gltextures[numTextures]);
   glBindTexture(0, gltextures[numTextures]);
   glTexImage2D(0, 0, GL_RGBA, eWidth , eHeight, 0, TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT, pcx.image.data8);

   imageDestroy(&pcx);


tex is my texture pointer, transCol is a parameter to the function call, in my test case 0 (which is the transparent color index afaik), eWidth and eHeight are calculated texture dimensions. I've tried with and without the COLOR0_TRANSPARENT flag, but neither works. The texture shows, but there's just no transparency. Anything I could be doing wrong here or somewhere else? Again, my apologies for bumping an old topic.

#175577 - elhobbs - Fri Dec 31, 2010 3:13 am

COLOR0_TRANSPARENT is for palettized textures only. In this case you are upsampling to 16 bit color. transCol should be the index of the transparent color in the palette not the color itself.

16 bit textures really use up a lot of VRAM. You will probably discover that you want to sticks with 8 bit or lower textures.

#175581 - SchmendrickSchmuck - Fri Dec 31, 2010 2:06 pm

Thanks for the reply, elhobbs.

Quote:
16 bit textures really use up a lot of VRAM. You will probably discover that you want to sticks with 8 bit or lower textures.


Doesn't the 'pcx.image.data8' part take care of that? If I understand the code correctly (I kinda copy-pasted this part) this should only return a pointer to the 8bit data, after which the image is deleted from memory with imageDestroy(&pcx). Also, removing the call to image8to16trans messes up the texture completely.

Quote:
transCol should be the index of the transparent color in the palette not the color itself.

Quote:
transCol is a parameter to the function call, in my test case 0 (which is the transparent color index afaik)


Unless I'm missing something totally obvious, I'm pretty sure I'm doing everything right...

#175582 - elhobbs - Fri Dec 31, 2010 2:57 pm

data8, data16, and data32 are a union. They all have the same value they just have different data types for convenience so you do not have to cast after the conversion functions run. Have you verified that index 0 is indeed the right alpha index or are you assuming? Aside from that it looks right to me.

#175584 - SchmendrickSchmuck - Fri Dec 31, 2010 3:45 pm

My palette in this case only has 3 colors, and I tried all of them. None seem to work. Maybe a palette always needs to be filled to 256? Any GL calls I might have missed? As far as I know all of my GL initialization and drawing are exactly the same as the examples.

#175586 - sverx - Fri Dec 31, 2010 4:09 pm

The COLOR0_TRANSPARENT flag indicates if you want texels containing color 0 to be drawn or not. You should specify it. And you should use color 0 into your PCX as transparent color, or post process the image after PCX decoding to swap the transparent pixels with 0 and vice-versa.
Of course you need Paletted Textures (formats 1,2,3,4 and 6, you probably want 4)

#175587 - SchmendrickSchmuck - Fri Dec 31, 2010 5:40 pm

Sverx, elhobbs, thank you both for your replies. It turns out that Photoshop seems to fill palettes back to front, starting at 255 instead of 0, even though the indices seem to be correct. Using GIMP instead fixes this issue. The COLOR0_TRANSPARENT flag doesn't seem to be necessary.