masking without blending?
i just got done reading a real shoddy tutorial on using textures with an alpha channel. i think i got the idea down, but i can't get it to work.
i have a 256x256 TIFF image with an alpha channel. here is how i am loading the texture:
[sourcecode]
windowTexture = [TextureObject textureObjectWithFile:[[NSBundle mainBundle] pathForResource:@"window" ofType:@"tif"] MipMap:FALSE ColorMode:GL_RGBA];
[/sourcecode]
TextureObject class
[sourcecode]
-(id)initWithPath:(NSString *)path isMipMap:(BOOL)mipMapTexture ColorMode:(GLuint)colorMode
{
NSBitmapImageRep *myTextureBitmap;
[super init];
myTextureBitmap=[NSBitmapImageRep imageRepWithContentsOfFile:path];
if(!myTextureBitmap)
NSLog([@"Failed to load texture: " stringByAppendingString:path]);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
if(mipMapTexture==FALSE) //build texture image (2^)
glTexImage2D(GL_TEXTURE_2D, 0, 3, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], 0, colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
else //build 2D mimpmap image (any size)
gluBuild2DMipmaps(GL_TEXTURE_2D, colorMode, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
return self;
}
[/sourcecode]
here is how i am drawing the object
[sourcecode]
glAlphaFunc(GL_NOTEQUAL, 0.0);
glEnable(GL_ALPHA_TEST);
glPushMatrix();
[windowTexture use];
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0,0.0);
glVertex3f(-12.0,0.0,12.0);
glTexCoord2f(1.0,0.0);
glVertex3f(-12.0,0.0,-12.0);
glTexCoord2f(1.0,1.0);
glVertex3f(12.0,0.0,-12.0);
glTexCoord2f(0.0,1.0);
glVertex3f(12.0,0.0,12.0);
glEnd();
glPopMatrix();
glDisable(GL_ALPHA_TEST);
[/sourcecode]
i have underlined different variables i've tried experimenting with.
for the colorMode:GL_RGBA variable, ive tried GL_RGB4,GL_RGBA,GL_RGB4,GL_RGBA2,GL_RGBA4,GL_RGBA8.
for the alphaFunc(GL_NOTEQUAL...) variable, ive tried GL_NOTEQUAL, and GL_GREATER both with numerous variables in the alpha ref param for glAlphaFunc. nothing seems to work. either the quad is all white, the quad is not visible, or the quad has a rainbow of colored madness all over it.
the tutorial i got this from was using TARGA files not TIFF. does the texture have to be .tga? i noticed when i view the image in Preview (MacOS X), the transparent pixels are black. When i view the image in Project Builder, the transparent pixels are transparent (i can see the window texture through it).
if it's a pixel format problem, here is mine:
[sourcecode]
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAStencilSize, 8
NSOpenGLPFAAlphaSize, 8
NSOpenGLPFAColorSize, 32
NSOpenGLPFADepthSize, 32
NSOpenGLPFAFullScreen,
0
[/sourcecode]
and just for reference, here's the initGL:
[sourcecode]
-(void)initGL
{
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glEnable(GL_SMOOTH);
glDepthFunc(GL_LESS);
glClearColor(0.2, 0.2, 0.4, 1.0);
glClearDepth(1.0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
[/sourcecode]
thanks a million to whoever can figure this one out.
i have a 256x256 TIFF image with an alpha channel. here is how i am loading the texture:
[sourcecode]
windowTexture = [TextureObject textureObjectWithFile:[[NSBundle mainBundle] pathForResource:@"window" ofType:@"tif"] MipMap:FALSE ColorMode:GL_RGBA];
[/sourcecode]
TextureObject class
[sourcecode]
-(id)initWithPath:(NSString *)path isMipMap:(BOOL)mipMapTexture ColorMode:(GLuint)colorMode
{
NSBitmapImageRep *myTextureBitmap;
[super init];
myTextureBitmap=[NSBitmapImageRep imageRepWithContentsOfFile:path];
if(!myTextureBitmap)
NSLog([@"Failed to load texture: " stringByAppendingString:path]);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
if(mipMapTexture==FALSE) //build texture image (2^)
glTexImage2D(GL_TEXTURE_2D, 0, 3, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], 0, colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
else //build 2D mimpmap image (any size)
gluBuild2DMipmaps(GL_TEXTURE_2D, colorMode, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
return self;
}
[/sourcecode]
here is how i am drawing the object
[sourcecode]
glAlphaFunc(GL_NOTEQUAL, 0.0);
glEnable(GL_ALPHA_TEST);
glPushMatrix();
[windowTexture use];
glBegin(GL_QUADS);
glNormal3f(0.0, 1.0, 0.0);
glTexCoord2f(0.0,0.0);
glVertex3f(-12.0,0.0,12.0);
glTexCoord2f(1.0,0.0);
glVertex3f(-12.0,0.0,-12.0);
glTexCoord2f(1.0,1.0);
glVertex3f(12.0,0.0,-12.0);
glTexCoord2f(0.0,1.0);
glVertex3f(12.0,0.0,12.0);
glEnd();
glPopMatrix();
glDisable(GL_ALPHA_TEST);
[/sourcecode]
i have underlined different variables i've tried experimenting with.
for the colorMode:GL_RGBA variable, ive tried GL_RGB4,GL_RGBA,GL_RGB4,GL_RGBA2,GL_RGBA4,GL_RGBA8.
for the alphaFunc(GL_NOTEQUAL...) variable, ive tried GL_NOTEQUAL, and GL_GREATER both with numerous variables in the alpha ref param for glAlphaFunc. nothing seems to work. either the quad is all white, the quad is not visible, or the quad has a rainbow of colored madness all over it.
the tutorial i got this from was using TARGA files not TIFF. does the texture have to be .tga? i noticed when i view the image in Preview (MacOS X), the transparent pixels are black. When i view the image in Project Builder, the transparent pixels are transparent (i can see the window texture through it).
if it's a pixel format problem, here is mine:
[sourcecode]
NSOpenGLPFADoubleBuffer,
NSOpenGLPFAAccelerated,
NSOpenGLPFAStencilSize, 8
NSOpenGLPFAAlphaSize, 8
NSOpenGLPFAColorSize, 32
NSOpenGLPFADepthSize, 32
NSOpenGLPFAFullScreen,
0
[/sourcecode]
and just for reference, here's the initGL:
[sourcecode]
-(void)initGL
{
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glEnable(GL_SMOOTH);
glDepthFunc(GL_LESS);
glClearColor(0.2, 0.2, 0.4, 1.0);
glClearDepth(1.0);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
}
[/sourcecode]
thanks a million to whoever can figure this one out.
Not too sure about the mipmaps, but I'm almost certain that your texImage2D() line should be
[sourcecode]
glTexImage2D(GL_TEXTURE_2D, 0, colorMode, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], 0, colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
[/sourcecode]
[sourcecode]
glTexImage2D(GL_TEXTURE_2D, 0, colorMode, [myTextureBitmap pixelsWide], [myTextureBitmap pixelsHigh], 0, colorMode, GL_UNSIGNED_BYTE, [myTextureBitmap bitmapData]);
[/sourcecode]
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES Texture Masking | airfire | 5 | 11,495 |
Nov 14, 2012 09:36 AM Last Post: toanNguyen |
|
| OpenGL ES Texture Masking | dalasjoe sin | 0 | 3,152 |
Apr 13, 2012 12:17 AM Last Post: dalasjoe sin |
|
| Masking without a stencil buffer? | Bachus | 12 | 10,764 |
Sep 2, 2010 02:42 PM Last Post: Skorche |
|
| Alpha Masking Problem | bonanza | 5 | 3,257 |
Jun 29, 2008 11:58 AM Last Post: maximile |
|
| general blending versus texture blending questions | WhatMeWorry | 2 | 4,255 |
Dec 7, 2006 02:43 PM Last Post: arekkusu |
|

