PDA

View Full Version : transparency problem in simple cube design



07-23-2004, 08:38 PM
Hi!!!

I will draw two cube...using the depth test.
But, last cub(Diameter 400) is transparency.
So i can see the first cub(Diameter 300).

Isn't the depth test achieved?

-------------- Source Code ----------------------

int CDlgScene::InitGL(GLvoid)
{
GLfloat ambientLight[]={0.3, 0.3, 0.3, 1.0};
GLfloat diffuseLight[]={0.4, 0.4, 0.4, 1.0};
GLfloat specular[]={0.5, 0.5, 0.5, 1.0};
GLfloat lightPos[]={-2000, -2000, 5000, 1.0};
GLfloat specref[]={0.5, 0.5, 0.5, 1.0};

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);

glEnable(GL_LIGHTING);

glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);

glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glEnable(GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
glMateriali(GL_FRONT, GL_SHININESS, 64);

glShadeModel(GL_SMOOTH);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

return TRUE;
}

int CDlgScene::DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, 705, 602);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1500, 1500, -1281, 1281, -1500, 1500);
gluPerspective(0.02, 705.0/602.0, 1, 3000);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(m_xPos, m_yPos, m_zPos-6000);
glRotatef(-90, 1, 0, 0);
glRotatef(m_xAngle, 1, 0, 0);
glRotatef(m_zAngle, 0, 0, 1);

glPushMatrix();

glColor3f(1.0, 1.0, 1.0);
glutSolidCube(300.0);

glColor3f(1.0, 0.0, 1.0);
glutSolidCube(400.0);

glPopMatrix();

return TRUE;
}

grimoire
07-24-2004, 12:16 PM
well you want to enable Blending with
glEnable(GL_BLEND);then use the blend func sort of like this
glEnable(GL_BLEND);
/*do all the transformations and rotations*/
glColor3f(1.0,1.0,1.0);
glutSolidCube(300.0);
glColor4f(1.0,0.0,1.0,0.5);/*half transparent*/
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glutSoliCube(400.0);

07-25-2004, 02:47 PM
NO!
I want two cube is not transparency...

Generally, if we use "depth_test" function then the first cube(diameter 300) is not disappeared...
But this code is not....

Why does this situation happen ???
I don't know......

grimoire
07-25-2004, 05:34 PM
it is hard to understand your english you must be using a translator. From what I understand you do not have the depth buffer enabled, and something is wrong. You have 2 cubes drawn on top of eachother, one is bigger than the other. Which one isn't being shown, or are they both are?

ypp
07-25-2004, 11:25 PM
Off topic:

>> glOrtho(-1500, 1500, -1281, 1281, -1500, 1500);
>> gluPerspective(0.02, 705.0/602.0, 1, 3000);

You must use only one of this functions: the first - for ortogonal projection, the second - for perspective.

>> gluPerspective(0.02, 705.0/602.0, 1, 3000);

You should use bigger value for angle (0.02).

-------------

If you are using glut, you can enable depth buffer like this:

glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH );