glColor4f alpha?

Apprentice
Posts: 13
Joined: 2009.06
Post: #1
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();
}
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
What does -[GameStateManager setCurrentlyBoundTexture:] look like? Does it sometimes disable GL_BLEND?
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2009.06
Post: #3
It's just a property

@synthesize currentlyBoundTexture = _currentlyBoundTexture;
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #4
Setting your alpha to 0.0 would lead me to expect that NONE of your images will be visible. What are the texture parameters?
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2009.06
Post: #5
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;
    
}
Quote this message in a reply
Member
Posts: 65
Joined: 2009.03
Post: #6
Hi Cirdan

Is something else being rendered enabling gl_color_array i.e.

Code:
glEnableClientState(GL_COLOR_ARRAY);

MikeD
Quote this message in a reply
Apprentice
Posts: 13
Joined: 2009.06
Post: #7
Nope, nothing like that.
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #8
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #9
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.
Quote this message in a reply
Member
Posts: 86
Joined: 2008.04
Post: #10
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #11
That's only true for RGBA textures, which is why you should read the man page.
Quote this message in a reply
Post Reply