Hi,
New to this board I am working in LWJGL but i’m positive that this question isn’t specific to that implementation.
I am trying to achieve a simple effect of having 3 transparent quads on top of each other. The first two use simple colour values which is fine, but when i try to apply a texture to the third quad (PNG with alpha channel) i begin to have problems. As it is, the third quad displays the texture on top of the other quads, but does not utilise the alpha channel.
I am sure something is not right with the way i am enabling and disabling GL_TEXTURE_2D. If i enable it once-only in glInit(), the 1st two boxes don’t show up. Or is it something to do with the blend function i’m callling – or both?
Ultimately i intend to move these simple quads into objects of their own – are there any major things i need to consider when adopting an OOP approach? (regarding gl_Enable calls etc)
Thanks for reading.
main routine:
// Clear the screen
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
// red square
GL11.glPushMatrix();
{
// select texture
GL11.glTranslatef(200f, 200f, 0.0f);
GL11.glColor4f(1f, 0f, 0f, 0.5f);
GL11.glBegin(GL11.GL_QUADS);
{
// anti clock wise
GL11.glVertex2f(0.0f, 0.0f); // top left
GL11.glVertex2f(250.0f, 0.0f); // top right
GL11.glVertex2f(250.0f, -250.0f); // bottom right
GL11.glVertex2f(0.0f, -250.0f); // bottom left
}
GL11.glEnd();
}
GL11.glPopMatrix();
// white square
GL11.glPushMatrix();
{
// select texture
GL11.glTranslatef(300f, 300f, 0.0f);
GL11.glColor4f(1f, 1f, 1f, 0.5f);
GL11.glBegin(GL11.GL_QUADS);
{
// anti clock wise
GL11.glVertex2f(0.0f, 0.0f); // top left
GL11.glVertex2f(250.0f, 0.0f); // top right
GL11.glVertex2f(250.0f, -250.0f); // bottom right
GL11.glVertex2f(0.0f, -250.0f); // bottom left
}
GL11.glEnd();
}
GL11.glPopMatrix();
// textured square
GL11.glPushMatrix();
{
// select texture
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture[0]); // Select Our Texture
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glTranslatef(400f, 400f, 0.0f);
GL11.glColor4f(1f, 0f, 0f, 0.8f);
GL11.glBegin(GL11.GL_QUADS);
{
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex2f(0.0f, 0.0f); // top left
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex2f(250.0f, 0.0f); // top right
GL11.glTexCoord2f(1.0f, -1.0f);
GL11.glVertex2f(250.0f, -250.0f); // bottom right
GL11.glTexCoord2f(0.0f, -1.0f);
GL11.glVertex2f(0.0f, -250.0f); // bottom left
}
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
}
GL11.glPopMatrix();
glInit:
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, mode.getWidth(), 0, mode.getHeight(), -100, 100);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);