blending difficulties
all i want is for some objects drawn to be transparent and some to not be. but i cant achieve this effect properly..but i can come mighty close. my technique is to draw the opaque objects first, then the transparent objects after. heres how i draw the transparent objects.
if(transparent) //object is transparent
{
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0f,1.0f,1.0f,0.5f);
}
glPushMatrix();
[self translateToPosition];
[self rotateToOrientation];
glScalef([scale getX],[scale getY],[scale getZ]);
glCallList([baseModel getDisplayList]);
glPopMatrix();
if(transparent)
{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
now what that does is draw the object fine, transparent (-looking anyway) . but say i were to place an opaque object in between the viewpoint and the transparent object. the transparent objects bleeds through the opaque object ruining the whole effect. i think im having problems understand the difference between source and destination in opengl. can someone please help? thanks.
if(transparent) //object is transparent
{
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glColor4f(1.0f,1.0f,1.0f,0.5f);
}
glPushMatrix();
[self translateToPosition];
[self rotateToOrientation];
glScalef([scale getX],[scale getY],[scale getZ]);
glCallList([baseModel getDisplayList]);
glPopMatrix();
if(transparent)
{
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}
now what that does is draw the object fine, transparent (-looking anyway) . but say i were to place an opaque object in between the viewpoint and the transparent object. the transparent objects bleeds through the opaque object ruining the whole effect. i think im having problems understand the difference between source and destination in opengl. can someone please help? thanks.
Change "glDisable(GL_DEPTH_TEST);" to glDepthMask(0) and "glEnable(GL_DEPTH_TEST);" to glDepthMask(1)
However if you really want to do it right you will need to draw the polygons in back-to-front order (not possible with display lists)
However if you really want to do it right you will need to draw the polygons in back-to-front order (not possible with display lists)
i dont understand when i read "draw polygons back to front." i see it everywhere. what is back and what is front? if back is -Z and front is +Z, then what if i have a camera that turns the opposite direction, then wouldnt back be +Z and front be -Z? oh im so confused
You have to calculate the object positions relative to the camera, then draw the furthest away to the nearest.
so let me see if i got you clearly. the camera's rotation is irrelevant, correct? i think of the camera position as the origin for drawing objects/polygons. i draw the farthest polygons from the camera first. when i say "farthest polygons", i mean all of the polygons a specified distance from the camera (in a 360∞ radius). is this right?
That'll work most of the time 
For absolutely perfect results, use the distance from the camera along the camera "front" vector to sort by. This is kinda counterintuitive, but it's due to how the depth buffer works.

For absolutely perfect results, use the distance from the camera along the camera "front" vector to sort by. This is kinda counterintuitive, but it's due to how the depth buffer works.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| general blending versus texture blending questions | WhatMeWorry | 2 | 4,258 |
Dec 7, 2006 02:43 PM Last Post: arekkusu |
|
| rotate and translate opengl difficulties | furballphat | 2 | 3,555 |
May 24, 2002 05:19 PM Last Post: furballphat |
|

