PDA

View Full Version : Transparency



link19
03-07-2001, 03:44 PM
Hi all,
I have a 3 sided cube (GL_QUADS with bottom, left, back sides). When i rotate the object, id like the opposite side (of each side) to be transparent. How can i accomplish this?
Thanks in advance.

Tone
03-08-2001, 12:51 AM
Just draw the front three faces as normal, with transparency turned off. When you want to draw the back three faces, enable transparency. If your question is how to enable transparency, then I suggest you check out the red book. It is online somewhere, although I don't know the address offhand. I am sure somebody on this board does. Hope this helps.

Tone

Moz
03-08-2001, 03:24 AM
The Red book can be found at http://helios.scripps.edu/library/SGI_bookshelves/SGIindex/SGI_Developer_OpenGL_PG.html

Got it with a search for OpenGL Programming Guide on www.northernlight.com (http://www.northernlight.com)

link19
03-08-2001, 08:52 AM
Okay. I did some research into this but still dont know if its possible. Ill make myself clearer. I dont have a six sided cube...i only have the 3 sides mentioned above. Id like these surfaces to be opaque from one side, but transparent from the other. So that if i rotate the object from the front to the back...all i can see is the outline of each side (cuz its transparent.)
Thanx again.

pleopard
03-08-2001, 09:59 AM
This is pretty simple to do actually ... Call glEnable(GL_CULL_FACE) for a one sided {transparent on one side} face and glDisable(GL_CULL_FACE) for a two sided face. If you use GL_QUADS to draw the faces and apply a texture to the facees then the one-sided version will be transparent on one side and opaque on the other. The two sided version will be opaque on both sides.

Lemme see if I can write a little pseudo-code for ya with a single face http://www.opengl.org/discussion_boards/ubb/smile.gif ...


bool doTwoSided;
double xLength,yLength;
MTexture faceTexture("CubeFace.bmp"); // C++ Texture class
...

glPushAttrib(GL_ENABLE_BIT);

glPushMatrix(); // Prepare for rotation

glRotatef(180.0,1,0,0); // flip face backwards

if (doTwoSided)
{
glDisable(GL_CULL_FACE);
}
else
{
glEnable(GL_CULL_FACE);
}

faceTexture.bind();

glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex2f(0.0f,0.0f);
glTexCoord2f(xLength,0.0f);
glVertex2f(xLength,0.0f);
glTexCoord2f(xLength,yLength);
glVertex2f(xLength,yLength);
glTexCoord2f(0.0f,yLength);
glVertex2f(0.0f,yLength);
glEnd();

glPopMatrix();

glPopAttrib();

[This message has been edited by pleopard (edited 03-08-2001).]

[This message has been edited by pleopard (edited 03-08-2001).]

link19
03-08-2001, 10:58 AM
Thx pleopard, that worked like a charm!!
Except...its the wrong side thats transparent. I have to rotate to see the side-i want it the other way...so how do i switch which side is transparent?

pleopard
03-08-2001, 06:47 PM
I edited the code above, notice the glRotate command...

link19
03-09-2001, 06:34 AM
Of course http://www.opengl.org/discussion_boards/ubb/biggrin.gif. Thanx again!

Fastian
03-10-2001, 08:08 AM
ofcourse you can also use glCullFace(GL_FRONT) or glCullFace(GL_BACK) to set the face you want to cull. in that case you wont need to rotate the cudbe http://www.opengl.org/discussion_boards/ubb/wink.gif

Fastian
03-10-2001, 08:12 AM
oops, it is actually glFrontFace(GL_CW)

i.e. you specify front face as GL_CW = clockwise or GL_CCW = counter clockwise. http://www.opengl.org/discussion_boards/ubb/smile.gif