[futurebasic] Re: [FB] Use of PNG Alpha channels for OpenGL

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Robert Purves <listrp@...>
Date: Sun, 20 Jan 2008 13:39:19 +1300
andy@... wrote:

> I am using Robert Purves (fantastic) OpenGL tutorial utilities in a
> section of my project. To create an alpha, it loads up two files,  
> the main
> graphic and the alpha channel, and combines them together for OpenGL  
> to
> display. (The alpha channel is used to define the irregular edges of  
> the
> graphic displayed). It works very well. But I am now loading up a  
> ton of
> graphics into my OpenGL program and its getting slower and s-l-o-w-e- 
> r to
> load. One way of speeding the load time would be use pre-loaded alpha
> channels which you can do within PNG type graphic files.
> Has anyone already tried to do this and have some code to share?

Image files are typically used in OpenGL as textures.
In my "OpenGLTestBed" (in FB4 Examples) this is done with  
MakeTextureFromFile(). That function reads an image file into a GWorld  
buffer, creates a texture with glGenTextures(), glBindTexture() and  
gluBuild2DMipmaps() or glTexImage2D(), then disposes of the buffer.  
Because the image is processed with QuickDraw, the original alpha  
component (if any) gets set to 1.0 for all pixels.

CoreGraphics (CG) makes it easy to retain the alpha component.

"Listing 9-4" in this URL:
is effectively a replacement for my old MakeTextureFromFile().

Robert P.