Archived

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

BLEND Question

This topic is 4990 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

Hello, Please have a look at this screen shot: http://www.habipaydogdu.com/scr.gif I want to make the arrow transparent(%50), but couldn''t do it. For testing, I quickly created a simple triangle(red one) and the blending worked on that. Here are my codes: The Arrow --------- glEnable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glColor4f( 1.0f, 1.0f, 1.0f, 0.5); glPushMatrix(); glBegin(GL_QUADS); // ... vertexes here glEnd(); glBegin(GL_TRIANGLES); // ... vertexes here glEnd(); glPopMatrix(); glDisable(GL_BLEND); *** Unfortunately, the arrow is apaque. I can''t see the behind. Here''s the code for the simple triangle: The Triangle ------------ glEnable(GL_BLEND); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glPushMatrix(); glColor4f( 1.0f, 0.0f, 0.0f, 0.5); glBegin(GL_TRIANGLES); // Vertexes here.. glEnd(); glDisable(GL_BLEND); glPopMatrix(); *** As you see everything are same. Why the arrow is opaque but the triangle is transparent?

Share this post


Link to post
Share on other sites
Okay, I reversed the order of rendering, and now, the Arrow is transparent but the triangle is not.

Now I have two questions;
1. What if I want to make both of the objects (the arrow and the triangle) transparent?

2. Okay, I start rendering objects from the furthest one, but in the program, with the keyboard inputs the objects change their places. For instance, an object (which was closest to the camera at the beginning) can go behind during the program run. What shall I do then?

Share this post


Link to post
Share on other sites
Sort by depth when the positions change. You always have to render transparent objects in a back-to-front order. Opaque objects should always be rendered front-to-back, of course, to take advantage of depth-testing. Basically: draw the opaque objects first, then draw the transparent objects in a back-to-front order (making sure blending is properly enabled, of course). This -should- work out fine. . .

Share this post


Link to post
Share on other sites