Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > OpenGL Alpha problem

OpenGL Alpha problem
Thread Tools
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 22, 2003, 02:27 AM
 
Hello ...

I'm having a problem getting OpenGL to properly display a textured quad using an alpha channel.

Below is a blown-up picture showing the difference between what I get (left, using OpenGL) and what I want (right, using a transparent NSImageView). The speckled stuff is a background.



Where the texture-image (whether a ".png" or a ".tif") is completely transparent or completely opaque, OpenGL renders it properly. Not so in the transitional regions between transparent and fully opaque. (There's a very faint, nearly transparent white glow about the top of the "peg".) OpenGL makes those regions unusually dark.

I've tried altering parameters of glBlendFunc() --the image shown uses glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)-- to no avail. I'm not sure what else to try.


Pointers?


Thanks,

DayLateDon
     
Mac Enthusiast
Join Date: Jan 2001
Status: Offline
Reply With Quote
Mar 24, 2003, 12:48 PM
 
I'm guessing that it has to do with premultiplication. NSImage (and hence, NSImageView) automatically premultiply your images if they're not already, but OpenGL does not.

I think Photoshop can export premultiplied images, but I've never tried it.
     
Dedicated MacNNer
Join Date: Nov 2000
Status: Offline
Reply With Quote
Mar 25, 2003, 05:26 AM
 
Hello ...

I haven't yet discovered a way to get Photoshop (5.5) to do what I need, but I found a handy utility called ImagePreUnMultiplier and dropped one of my problematic images onto it. I tried pre-multiplying and pre-unmultiplying.

The results: pre-multiplying caused the "NSImageView" version of the image to look exactly like the old OpenGL version (dark at the semi-transparent stages) and the OpenGL version to look even worse; pre-un-multiplying caused the new NSImageView version to look absolutely creepy, but made the new OpenGL version to look the way I want. Success!

Well, almost. There's a loss of definition around the edges. (It's especially noticeable in images involving text.) That's annoying.

What's worse: My app uses the same batch of images in NSImageViews as well as OpenGLViews, and the NSImageViews show the absolutely creepy renditions. There are far too many images to duplicate and have an nsimage-compatible version and opengl-compatible version of each one.


Is there a way to have NSImage hand off a pre-multiplied (or pre-un-multiplied ... I'm getting this all confused at this point) version of a file to OpenGL? The NeHe sample code loads a file into NSBitmapImageRep and builds a texture from that. Would a different strategy help?


Thanks ...

DayLateDon
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2