Archived

This topic is now archived and is closed to further replies.

alpha blending problem

This topic is 5173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ppl i have problem with alpha blending.. i succesfully blend bitmap.bmp and bitmapalpha.bmp for the first time when it is drawed... but every other time i call my list Tree or any other it doesn''t blend correctly..Plz if anyone can help here is the code i use... GLvoid BuildLists() { Tree=glGenLists(2); glNewList(Tree, GL_COMPILE); glBindTexture(GL_TEXTURE_2D, texture[3]); glBegin(GL_QUADS); // Start Drawing A Textured Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.2f, 0.0f); // Bottom Left glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.2f, 0.0f); // Bottom Right glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.2f, 0.0f); // Top Right glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.2f, 0.0f); // Top Left glEnd(); glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, texture[4]); glBegin(GL_QUADS); // Start Drawing A Textured Quad glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.2f, -0.2f, 0.0f); // Bottom Left glTexCoord2f(1.0f, 0.0f); glVertex3f( 0.2f, -0.2f, 0.0f); // Bottom Right glTexCoord2f(1.0f, 1.0f); glVertex3f( 0.2f, 0.2f, 0.0f); // Top Right glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.2f, 0.2f, 0.0f); // Top Left glEnd(); glEndList(); } int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBlendFunc(GL_DST_COLOR,GL_ZERO); // Blend Screen Color With Zero (Black) glEnable(GL_BLEND); // Enable Blending glDisable(GL_DEPTH_TEST); // Disable Depth Testing glLoadIdentity(); glTranslatef(0.5f,0.15f,-2.0f); glCallList(Tree); glLoadIdentity(); glTranslatef(-0.5f,0.7f,-2.0f); glCallList(Tree); glEnable(GL_DEPTH_TEST); // Enable Depth Testing glDisable(GL_BLEND); }

Share this post


Link to post
Share on other sites
I got it. It''s pretty simple.

1) you set the blendfunc to GL_DST_COLOR,GL_ZERO

2) you call the list for the first time.
2.1) the first part of the list is rendered with GL_DST_COLOR,GL_ZERO
2.2) in the list you change to GL_ONE, GL_ONE
2.3) you draw the second part with GL_ONE, GL_ONE

3) you translate/rotate some

4) you call the list for the second time
4.1) the first part is drawn with GL_ONE, GL_ONE (it was set above in (2.2) and you didn''t change it back to GL_DST_COLOR,GL_ZERO)
4.2) You change to GL_ONE, GL_ONE. This doesn''t do anything since it is already GL_ONE, GL_ONE.
4.3) you draw the second part of the list

The solution: At the beginning of the list, set the belndmode to GL_DST_COLOR,GL_ZERO


Sander Maréchal
[Lone Wolves Game Development][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

Share this post


Link to post
Share on other sites