alpha blending problem

Started by
3 comments, last by Syrus 20 years, 6 months ago
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); }
Advertisement
GLvoid BuildLists(){Tree=glGenLists(2);glNewList(Tree, GL_COMPILE); 

Why are you generating two lists while you call glNewList()/glEndList() only once???? Try changing to glGenLists(1)

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

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Yes there should be "1"..my mistake..

I fixed it and it still doesn''t work.
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]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Thx man it works now pretty fine.

This topic is closed to new replies.

Advertisement