PDA

View Full Version : Transparent QUADS



djavan
02-16-2003, 03:45 PM
Hi
I am trying to draw a cube (each side with a different color) with one of its sides (i.e. the top) being transparent and the rest being solid (so that when I rotate it, I only see the inside when the transparent side comes to view)

my code (in VB) for the TOP-SIDE looks like this:

glPushMatrix
glColor3ub 160, 130, 50
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glBegin bmQuads
glVertex3f xMn, yMn, Z
glVertex3f xMx, yMn, Z
glVertex3f xMx, yMx, Z
glVertex3f xMn, yMx, Z
glEnd
glDisable GL_BLEND
glPopMatrix

But it doesn't draw anything at all!?!?

Can you please tell me what am I missing?
Thanks a lot.

nexusone
02-16-2003, 05:24 PM
Note you have to have a alpha value set for blend to work correctly.

With glColor3f you only set the color values and the default is alpha of 1, which is non-transparent.

When you draw your cube you should set each sides color and alpha.
alpha = 1.0 non-transparent, 0.3 = simi-transparent (adjust until you get the amount of transparency)

This is how I setup stuff like that:

float cube_color[6][4] = { { 1, 1, 1, 1.0 }, { 1, 1, 1, 1.0 }, { 1, 1, 1, 1.0 }, { 1, 1, 1, 1.0 }, { 1, 1, 1, 1.0 }, { 1, 1, 1, 0.3 }};

inside you cube draw routine.

glColor4fv( cube_color[side] );

or with your example something like this:
Not sure the unsigned bit coverted right.

glColor4ub 255 255 255 40 white with a low alpha for simi-tranparency. I use white for transparent area's, unless you want a color filter effect.


Originally posted by djavan:
Hi
I am trying to draw a cube (each side with a different color) with one of its sides (i.e. the top) being transparent and the rest being solid (so that when I rotate it, I only see the inside when the transparent side comes to view)

my code (in VB) for the TOP-SIDE looks like this:

glPushMatrix
glColor3ub 160, 130, 50
glEnable GL_BLEND
glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
glBegin bmQuads
glVertex3f xMn, yMn, Z
glVertex3f xMx, yMn, Z
glVertex3f xMx, yMx, Z
glVertex3f xMn, yMx, Z
glEnd
glDisable GL_BLEND
glPopMatrix

But it doesn't draw anything at all!?!?

Can you please tell me what am I missing?
Thanks a lot.



[This message has been edited by nexusone (edited 02-16-2003).]

djavan
02-16-2003, 08:46 PM
With many thanks for your help and reply, I applied your suggestion and still this particular QUAD is not displayed. (I even moved the glColor4ub down to after the glBlendFunc call, but still the same)!?!?

I appreciate your advice.

djavan
02-17-2003, 05:46 AM
Hi again!

I had a mistake in implementing your suggestion and now it works but there is still a little problem for which I highly appreciate your help.

In order to see the effect of this "Glass Wall", I separated it from my cube and made it a separate rectangle (QUAD) and the cube is now can be drawn either solid with edges or edges only with a little sphere at each vertex.
In this case, I expect to see the cube from behind my "Glass Wall" with an added shade from the color of glass when I rotate my image (the entire picture).
The problem that I encounter is that it works as I expect ONLY when I draw the cube in the latter form (i.e. edges w. vertices). But the "Glass Wall" (sort of) goes behind the cube when it is solid with edges (instead of having the G.W. shading in front of the cube).

Can you please help me on this?
With my highest appreciation for your help.

shinpaughp
02-17-2003, 08:41 AM
Do you have depth testing enabled?
glEnable(GL_DEPTH_TEST)

djavan
02-17-2003, 10:19 AM
With thanks for your help, YES. I have the following two lines:

glClearDepth 1
glEnable GL_DEPTH_TEST

when OpenGL is started. Also, if it matters, I do not have any glMatrixMode in my program (so it is what ever the default is, which I am assuming to be ModelView?!?)

djavan
02-17-2003, 10:47 AM
Hi again

i just noticed that when I "LookAt" my picture from the "negative quarter" (i.e. -1,-1,-1) everything is OK. But when I go to the "positive quarter" (i.e. 1,1,1) the cube comes in front of the glass (although from the coordinates it should be the other way round).

Also, if it matters, I am drawing all my rectangles (i.e. the cube-sides and the glass wall) twice: once clockwise and once unticlockwise, with regards to the order of their vertices ( I had to do this because otherwise from some "viewpoints" the color of the rectangle didn't show up and it was simply white!?!?)

Thanks again for the help.

djavan
02-17-2003, 06:29 PM
Hi again!

I found the problem!
I had to disable DepthTest.

It is working great and thank you all.