Advertisement

blending properly

Started by February 23, 2003 12:36 PM
1 comment, last by fizbanx 22 years ago
In the blending tutorial (Lesson 8), it is mentioned that in order to properly blend, any non-blended objects should be drawn afterwards, in ascending z-coord order. I believe I understand the basics, but I''m not quite sure how to change it from drawing it as blended once I get to an object that I want to appear as opaque. Here is what I have: (I already drew a few blended objects above this code) if(blend) { glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); } glBindTexture(GL_TEXTURE_2D, texture[filter]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, -2.0f, 2.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -2.0f, -2.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -2.0f, -2.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, -2.0f, 2.0f); glEnd(); if(blend) { glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); }
You got it exactly wrong! It''s opposite. Draw non-blended objects FIRST, followed by blended objects in DESCENDING z-order (far to near).

Also, don''t turn off depthtesting. Instead turn off only depth-writes. In your code, replace the enable/disable depthtest with glDepthMask(true/false).

Third, in order to have a polygon blend, it needs have an alpha color set! So when enabling blending set glColor4f(1.0f, 1.0f, 1.0f, 0.5f) and when disabling blending, set all colors back to 1.0f.

Hope this helps!

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

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

Advertisement
Thanks!

This topic is closed to new replies.

Advertisement