glColor4f alpha?
I'm trying to get alpha working for some simple effects for the menu. But I found a problem, only some of my images accept the alpha value from glColor4f. In my image drawing code I set the alpha to 0.0f. Two of my 5 images are invisible. What would cause this only on those images(They all use the same draw routine)?
Code:
- (void)renderAtPoint:(CGPoint)aPoint quadVertices:(Quad2f*)aVertices textureCoords:(Quad2f*)aTextureCoords {
// Save the current matrix to the stack
glPushMatrix();
// Set the rotation of our image
glTranslatef(aPoint.x, aPoint.y, 0.0f);
glRotatef(-_rotation, 0.0f, 0.0f, 1.0f);
glTranslatef(-aPoint.x, -aPoint.y, 0.0f);
// Set the color filter
glColor4f(_colorFilter.r, _colorFilter.g, _colorFilter.b, 0.0f);
// Enable Vertex Array rendering
// Enable Texture Coord Array use
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Enable texturing
glEnable(GL_TEXTURE_2D);
// Make sure we aren't rebinding the texture
if([_texture name] != [[GameStateManager sharedGameStateManager] currentlyBoundTexture]) {
[[GameStateManager sharedGameStateManager] setCurrentlyBoundTexture:[_texture name]];
glBindTexture(GL_TEXTURE_2D, [_texture name]);
}
// Setup the vertex pointer to our coordinates
glVertexPointer(2, GL_FLOAT, 0, aVertices);
// Setup the texture coords pointer to our coords
glTexCoordPointer(2, GL_FLOAT, 0, aTextureCoords);
// Setup our blend function
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Draw the vertices
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glDisable(GL_VERTEX_ARRAY);
// Load the matrix back from the stack
glPopMatrix();
}
What does -[GameStateManager setCurrentlyBoundTexture:] look like? Does it sometimes disable GL_BLEND?
It's just a property
@synthesize currentlyBoundTexture = _currentlyBoundTexture;
@synthesize currentlyBoundTexture = _currentlyBoundTexture;
Setting your alpha to 0.0 would lead me to expect that NONE of your images will be visible. What are the texture parameters?
I'm using the Texture2D class also
Code:
- (void)initOpenGL {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
// We want landscape so rotate the view, and swap the screen width & height
glRotatef(-90.0f, 0, 0, 1);
glOrthof(0.0f, _screenBounds.size.height, 0, _screenBounds.size.width, -1.0f, 1.0f);
//glRotatef(20, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND_SRC);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnableClientState(GL_VERTEX_ARRAY);
glDisable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
_glInitialized = YES;
}
Hi Cirdan
Is something else being rendered enabling gl_color_array i.e.
MikeD
Is something else being rendered enabling gl_color_array i.e.
Code:
glEnableClientState(GL_COLOR_ARRAY);MikeD
Nope, nothing like that.
They all may be using same draw routine but generally problems like that caused by some OpenGL state being set somewhere else in your code and not being reset properly in certain scenarios.
I suggest you check the internal format of your textures. Then read the TexEnv tables in the man page to see what happens to RGB and A.
Also, make sure you are using
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
instead of
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
the latter will simply overwrite the incoming fragment, ignoring any color material set on it.
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
instead of
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
the latter will simply overwrite the incoming fragment, ignoring any color material set on it.
That's only true for RGBA textures, which is why you should read the man page.

