Archived

This topic is now archived and is closed to further replies.

Colorkey problems (using glAplhaFunc())

This topic is 5599 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m trying to make a color key using:
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, GL_ZERO); 
But all I get is a black screen (e.g nothing is drawn). I''m extracting a frame from a bmp then adding a aplpha chanel like this:
  
// Extract the frame

for(y = 0; y < texHeight; y++)
{
	for(x = 0; x < texWidth * 3; x += 3)
	{
		frame[j] = bitmap->Image((bitmap->Width()*3*(yPos+y))+((xPos*3)+x));
		frame[j+1] = bitmap->Image((bitmap->Width()*3*(yPos+y))+((xPos*3)+x)+1);
		frame[j+2] = bitmap->Image((bitmap->Width()*3*(yPos+y))+((xPos*3)+x)+2);
		
		// Check if it''s the color key (if so sett to completely transparent)

		if((frame[j] == COLORKEY_RED) && (frame[j+1] == COLORKEY_GREEN) 
			&& (frame[j+2] == COLORKEY_BLUE)) {
			frame[j+3] = 0;
		}
		else {
			frame[j+3] = 255;
		}

		j += 4;
	}
}

glGenTextures(1, &texID[frameNr]);
glBindTexture(GL_TEXTURE_2D, texID[frameNr]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 
			 0, GL_RGBA, GL_UNSIGNED_BYTE, frame);
  
The whole frame is drawn correctly (with the color I don''t want) if I don''t enable GL_ALPHA_TEST but when I do nothing at all is drawn. I have also tried with comenting out the if case and just setting frame[j+3] = 255; but that doesn''t help either. What am I doing wrong? Thanks in advance Spearhawk

Share this post


Link to post
Share on other sites
Hehe, never mind that. The code works.
I must have been more tired than I thought, I was working with a overloaded fuction, and of course it was the other "copy" of the fuction than the one that I worked on that was called

Share this post


Link to post
Share on other sites