glCopyTexImage2D -and- Alpha Testing

hello,

The glCopyTexImage2D() is working perfectly to render a small image to a texture. The one problem is that I cannot apply the GL_ALPHA_TEST to the texture to get some transparency.

I’m using GL_RGBA, clearing to a black background, then drawing some light images on the viewport.

What might be going wrong?

Thanks.

Here’s some code

//create an empty texture…
GLuint texnum;
glGenTextures(1, &texnum);
glBindTexture(GL_TEXTURE_2D, texnum);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SIZEX, SIZEY, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

//render to texture…
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glViewport (0, 0, SIZEX, SIZEY);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glMatrixMode(GL_PROJECTION); glLoadIdentity();
glOrtho(0, SIZEX, 0, SIZEY, -1, 1);
draw_text(white, “Testing!”);
glBindTexture(GL_TEXTURE_2D, texnum);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, SIZEX, SIZEY, 0);

//draw texture to screen…
glColor4ub(255,255,0,255);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
glBindTexture(GL_TEXTURE_2D, texnum);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex2i(left, bottom);
glTexCoord2f(0.0f,1.0f); glVertex2i(left, top);
glTexCoord2f(1.0f,1.0f); glVertex2i(right,top);
glTexCoord2f(1.0f,0.0f); glVertex2i(right,bottom);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_ALPHA_TEST);

I’m getting no transparency in my final draw-to-screen step, just white text on a solid black rectangle.

I would like to see the white text areas, but no rectangle.

Thanks.

That would mean the alpha value is larger than 0.1
This depends on the TexEnv mode. Are you using GL_DECAL?
Also, use glCopyTexSubImage2D instead just for updating a texture.

I’m going to guess it would be better to have
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

And you have to know what draw_text does exactly. Good luck!

I tried the things you mentioned, V-man, but no luck.

My Alpha-testing works great in many other areas of the program. The draw_text() function even uses alpha-testing to get the white text to the texture viewport.

I’ll keep trying things until I get it to work.

Where do you call glEnable( GL_TEXTURE_2D ) ? Is blending disabled?