blending difficulties

ghettotek
Unregistered
 
Post: #1
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.
Quote this message in a reply
Member
Posts: 164
Joined: 2002.04
Post: #2
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)
Quote this message in a reply
ghettotek
Unregistered
 
Post: #3
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 Wacko
Quote this message in a reply
henryj
Unregistered
 
Post: #4
You have to calculate the object positions relative to the camera, then draw the furthest away to the nearest.
Quote this message in a reply
ghettotek
Unregistered
 
Post: #5
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
That'll work most of the time Smile

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.
Quote this message in a reply
ghettotek
Unregistered
 
Post: #7
damn i didnt even try Davids code. that worked perfectly David. thanks man. funny i had that code in there just commented cuz i didnt think it worked.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  general blending versus texture blending questions WhatMeWorry 2 5,133 Dec 7, 2006 02:43 PM
Last Post: arekkusu
  rotate and translate opengl difficulties furballphat 2 4,179 May 24, 2002 05:19 PM
Last Post: furballphat