PDA

View Full Version : Cocoa loaded textures have white edges


Jake
2005.05.05, 08:06 PM
I use Cocoa to load my textures for GL Golf, and for my trees I just use a simple pass fail test for transparencies instead of blending. Before tiger my transparencies had black edges, found below. They looked cool because they gave the edges some detail. BUT now tiger has made those edges white, which looks horrible.

http://nuclearnova.com/images2/glgolf1.1.jpg

How can I fix this. Here is my code to load the texture (PNG with alpha)



glGenTextures( NUMBER_OF_TEXTURES, &texture[0] );

for (textureOn=0; textureOn<NUMBER_OF_TEXTURES; textureOn++)
{

image[textureOn] = [[NSImage alloc] initWithContentsOfFile: path[textureOn]];
imageRep[textureOn] = [[NSBitmapImageRep alloc] initWithData: [image[textureOn] TIFFRepresentation]];

// Create mipmapped texture with an alpha
if ((mode[textureOn] == 2) && (alph[textureOn] == TRUE))
{
glBindTexture( GL_TEXTURE_2D, texture[ textureOn ] );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST );
gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, size[textureOn], size[textureOn], GL_RGBA,GL_UNSIGNED_BYTE, [imageRep[textureOn] bitmapData]);
}



Can I still use this method or do I need to get a new loader (if so links would be greatly appreciated)

kelvin
2005.05.05, 09:02 PM
I have a similar issue with addative blending of my textures.
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
worked fine in Panther, now it ghosts badly and looks like crap.

OneSadCookie
2005.05.05, 09:02 PM
Ryan, that was very unhelpful. both points are just plain wrong, and don't help the question. Don't post if you have NFI what you're talking about.

Jake, the problem lies in the filtering. It surprises me that you've only just discovered it with Tiger; perhaps your textures are no longer being premultiplied at load time?

See the threads about premultiplied alpha (Fenris had a good one) for the solution to your problem.

Puzzler183
2005.05.05, 09:08 PM
Eh, don't be too harsh on Ryan. Admittedly though, Ryan is pretty blatantly wrong. Mipmaps are very very good if constructed well because for the price of 1/3 more memory, you get a speed boost and your results can look much better (especially with trilinear filtering). It's very important to pay attention to their construction though or make them by hand.

arekkusu
2005.05.06, 12:29 AM
The thing to be aware of here is that NSImage now supports ARGB format, in addition to RGBA. And non-premultiplied alpha, in addition to premultiplied. This is GOOD because ARGB is what the hardware actually uses.

Old apps (compiled on 10.3) will work just as always, but if you rebuild on Tiger, you might get the new behavior. Read the docs.

kelvin
2005.05.06, 12:49 AM
yep, just found this out. makes things easier for me I guess.

Jake
2005.05.06, 01:17 PM
EDIT : After reading page two of fenris's post I found this

I just put a photoshop "stroke" effect on the outside of my image (rgba) that has a color similar to the image and then put the transparency down to about 2-5%, more if I want a sort of outline. Snowball is a bit sloppy in places, but generally you won't see any halos.

That seamed to eliminate the halo to almost not noticeable.

Thanks for the info, that helps my knowledge of OpenGL alot!