Draw Object non- Transoprent

Hi all ,

I have simple application which read VRML file , and draw it using OpenGL (In Tao Framework).

My program contained init function , Perspective init function , light init function and finely the Render function which draw triangles ( parsed from the VRML file).

My VRML model described same device ( like door handle) and same screws within the device. those screws are hidden .

My problem is that the opengl draw my handle transparently and the screws which located inside the device are displayed.

I try all most everything include enabling the depth_test.

I guess I miss same stupid declaration.

Best regards , Leon.


It could be a lot of things, from incorrectly specifying your geometry or matrices, to incorrect alpha values with certain states enabled. It’s hard to guess what the problem in your code is.

That said it could be a problem with winding order. You’ve said you’ve enabled a lot of things, does that include glEnable(GL_CULL_FACE) ? If so, you might want to comment it out. If there is a winding inconsistency, disabling back face culling should demonstrate it.

First , thanks for your replay.

As you thought ,I did enabled the GL_CULL_FACE in my program. Unfortunately comment this line out or disabling the GL_CULL_FACE didn’t solve the problem (the inside part in the device are still displayed )

Is there any chance that the problem occur because my draw method use simple OpenGL commands ( i didn’t use Glut or any other utility , i draw into Tao simplecontrol).

I’m apologise for been a newbe but i didn’t understand the meaning of “winding” ?

Thanks again.


Can you post a screenshot? Are you using glEnable(GL_BLEND) somewhere?

a screenshot to my drawing:


In the following link you can see my device. the small balls are located within the device.
I read my device using VRML viewer and it display the following :
you can see clearly that the balls are hidden.

also ,I didn’t enable the GL_BLEND.

Thanks ,Leon

I think I know what is my problem exactly. Its has to do with the order I draw the items. The big device draw first always and the other small balls draw after that. therefore its look like the big device is transparent.
So i guess that i’m doing something wrong. here is my Code :

The Init Function :

public void InitOpenGLImageGeneretor(double ImageRadius ,double focalDistance)
    Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    m_dfocalDistance = focalDistance;
    m_dImageRadius = ImageRadius;
    Gl.glViewport(-500, -500, 500, 500);
    Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // enable lighting for front
    Gl.glLightModeli(Gl.GL_FRONT, Gl.GL_TRUE);
    // material have diffuse and ambient lighting 
    Gl.glColorMaterial(Gl.GL_FRONT_AND_BACK, Gl.GL_DIFFUSE);
    // enable color

    float[] ambientProperties = { 0.0f, 0.0f, 0.5f, 0.0f };
    float[] diffuseProperties = { 0.0f, 1.0f, 1.0f, 0.0f };
    float[] specularProperties = { 1.0f, 1.0f, 1.0f, 0.0f };

    Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambientProperties);
    Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, diffuseProperties);
    Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, new float[] { 1.0f, 1.0f, 1.0f });
    //// enable light 0

    //// enable light 1
     // Init perspectibe 

My Rendering method :

public void DrawVRML(
List<VRMLModel> VRMLList,
Transform3D[] transList,
Transform3D globalTrans)
Gl.glViewport(0, 0, simpleOpenGlControl.Width 
                    , simpleOpenGlControl.Height );
SetView( );

m_iDispList = Gl.glGenLists(1);
Gl.glNewList(m_iDispList, Gl.GL_COMPILE_AND_EXECUTE);

// Run foreach vrml model
for (int iModel = 0; iModel < VRMLList.Count; ++iModel)
    // Get the current model transformation
    Transform3D trans = transList[iModel];

    // Compuse the current model transformation with the global transformation
    trans = globalTrans.Compose(trans);

    // Current vrml model for drawing
    VRMLModel vrml = VRMLList[iModel];

    //// Set a default material
    float[] a = { 0.0f, 0.0f, 0.8f,0.0f };
    Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_AMBIENT, a);
    float[] d = { 0, 0.8f, 0.8f, 1.0f };

    Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_DIFFUSE, d);
    Gl.glMaterialf(Gl.GL_FRONT, Gl.GL_SHININESS, 0.3f);
    Gl.glMaterialfv(Gl.GL_FRONT, Gl.GL_SPECULAR, d);

    // Show the models normal
    bool ShowNormals = true;

    // Normal Calculation for current model

    // Begin drawing the triangels
    for (int trianleIndex = 0; trianleIndex < 
          vrml.triangles.Count; ++trianleIndex)

        // Get current triangle vertices        
        IndexesTriangle tri = vrml.triangles[trianleIndex];
        Vec3D v1 = vrml.vertices[tri.v1];
        Vec3D v2 = vrml.vertices[tri.v2];
        Vec3D v3 = vrml.vertices[tri.v3];

        // apply transformation to every model so that they sit well together
        // in the 3D world.
        trans.Apply2Vec3D(ref v1);
        trans.Apply2Vec3D(ref v2);
        trans.Apply2Vec3D(ref v3);

        // Draw the Vertex
        Vec3D n = vrml.normals[tri.v1];
        trans.RotationMatrix.MultVec3D(ref n);
        Gl.glNormal3f(n.x, n.y, n.z);
        Gl.glVertex3f(v1.x, v1.y, v1.z);

        n = vrml.normals[tri.v2];

        trans.RotationMatrix.MultVec3D(ref n);
        Gl.glNormal3f(n.x, n.y, n.z);
        Gl.glVertex3f(v2.x, v2.y, v2.z);

        n = vrml.normals[tri.v3];

        trans.RotationMatrix.MultVec3D(ref n);
        Gl.glNormal3f(n.x, n.y, n.z);
        Gl.glVertex3f(v3.x, v3.y, v3.z);


What i’m dowing wrong?
Thanks agine ,Leon

You have to be sure that you have a valid OpenGL context before using any of the GL commands. At the moment Gl.glEnable(Gl.GL_DEPTH_TEST);
is called, you probably don’t have a valid GL context because glutInit is called afterwards.

I don’t know at which point glut returns a valid context, either at glutInit or glutCreateWindow…

Thank you all for yours reply

I finally understand what was wrong with my code.
The gluPerspective get bad Znear and Zfar values. The Z values was too big , there for the OpenGl handled the Zbuffer badly.
Calculation the minimum and maximum z values and used then in the gluPerspective solve the problem.

The gluPerspective(angleOfView, 1.0, minZ, MaxZ );

Thanks again .