PDA

View Full Version : Extreme newbie alert - Blending question



r_pyon
10-13-2004, 10:01 PM
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);

Dol AI with 3D Bone system
10-13-2004, 10:21 PM
You blend by Alpha as me.

Do you have problem with the last object matrix?

r_pyon
10-13-2004, 11:01 PM
Hi Dol,

Sorry i don't quite understand what you mean by 'blend by Alpha as me' -- but yes, i am having trouble with the last object matrix :confused:

10-14-2004, 12:12 AM
Check out the FAQ.

http://www.opengl.org/resources/faq/technical/#indx0150

Dol AI with 3D Bone system
10-14-2004, 03:07 AM
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=017373

Dol AI with 3D Bone system
10-14-2004, 03:11 AM
Help me my problem. My problem about blending object if I enable blend object 2 the object 1 is show but the object 3, 4, 5... is not show.

Why?

10-14-2004, 11:20 AM
DOL AI WITH 3D BONE SYSTEM:

Would you PLEASE stop hijacking other peoples threads.

Thank you very much.