BLEND Question
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?
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?
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?
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. . .
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement