PDA

View Full Version : glCopyTexImage2D -and- Alpha Testing



gordon1
05-13-2009, 12:15 AM
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.

gordon1
05-13-2009, 08:23 AM
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_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,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.

V-man
05-14-2009, 05:58 AM
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!

gordon1
05-14-2009, 10:06 AM
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.

dletozeun
05-15-2009, 12:59 AM
Where do you call glEnable( GL_TEXTURE_2D ) ? Is blending disabled?