Hi all,
The problem is the next:
I’m trying to create a billboard texture from a sphere but I can’t get copy the alpha channel correctly using glCopyTexImage2d.
Code goes here:
void generateSphereBillboard()
{
glGenTextures(1,&sphereTexture);
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(65,1,0,10);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt(0, 0, 6, 0, 0, 1, 0, 1, 0);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, 256,256);
GLUquadricObj *pObj = gluNewQuadric();
gluQuadricNormals(pObj,GL_SMOOTH);
gluSphere(pObj,1,16,16);
gluDeleteQuadric(pObj);
glBindTexture(GL_TEXTURE_2D,sphereTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 256, 256, 0);
glPopAttrib();
glPopMatrix(); // pop modelview
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
The image is copied to texture memory successfully but when I draw it, the billboards aren’t transparents ( I guess alpha channel is bad?)
The base code to draw the billboard is the next:
void DrawBillboard(float[] a,float [] b, float []c, float [] d)
{
glDisable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,sphereTexture);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL,0);
glBegin(GL_QUADS);
glTexCoord2f(0,0);glVertex3fv(a.getValue());
glTexCoord2f(1,0);glVertex3fv(b.getValue());
glTexCoord2f(1,1);glVertex3fv(c.getValue());
glTexCoord2f(0,1);glVertex3fv(d.getValue());
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
glEnable(GL_LIGHTING);
}
I don’t understand why the same code using a TGA file with alpha channel from the disk works fine. Any idea?
Thanks a lot!