Cocoa loaded textures have white edges

Member
Posts: 508
Joined: 2002.05
Post: #1
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.

[Image: glgolf1.1.jpg]

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

Code:
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)
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #2
I have a similar issue with addative blending of my textures.
Code:
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
worked fine in Panther, now it ghosts badly and looks like crap.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Luminary
Posts: 5,125
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #4
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.
Quote this message in a reply
Sage
Posts: 1,231
Joined: 2002.10
Post: #5
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.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #6
yep, just found this out. makes things easier for me I guess.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 508
Joined: 2002.05
Post: #7
EDIT : After reading page two of fenris's post I found this

Quote: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!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Create Aquaria-like terrain- texturing edges AndyKorth 3 5,353 Jul 31, 2011 08:13 PM
Last Post: FlamingHairball
  [SOLVED]OpenGL edges of textures mk12 2 3,622 Sep 2, 2010 08:07 PM
Last Post: mk12
  Replacing edges with degenerate quads (for shadow volumes) Coyote 9 6,402 Jan 15, 2010 07:08 PM
Last Post: Coyote
  Loading and using textures with alpha in OpenGL with Cocoa corporatenewt 4 5,078 Dec 8, 2007 02:06 PM
Last Post: Malarkey
  loading textures - cocoa openGL mDmarco 20 8,331 Aug 28, 2007 08:48 PM
Last Post: OneSadCookie