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.

Leon.Noah@Gmail.com

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.

Leon.

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

a screenshot to my drawing:

http://img386.imageshack.us/img386/1351/deviceji4.jpg

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 :
http://img386.imageshack.us/img386/3663/device2pm3.jpg
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.glEnable(Gl.GL_DEPTH_TEST);
    Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    m_dfocalDistance = focalDistance;
    m_dImageRadius = ImageRadius;
    Glut.glutInit();
    Gl.glViewport(-500, -500, 500, 500);
    Gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    Gl.glShadeModel(Gl.GL_SMOOTH);
    Gl.glEnable(Gl.GL_LIGHTING);
    // 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
    Gl.glEnable(Gl.GL_COLOR_MATERIAL);

    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_SPECULAR,specularProperties);
    Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, new float[] { 1.0f, 1.0f, 1.0f });
    //// enable light 0
     Gl.glEnable(Gl.GL_LIGHT0);

    //// enable light 1
    Gl.glEnable(Gl.GL_LIGHT1);
    
     // Init perspectibe 
     SetView();      
}

My Rendering method :

public void DrawVRML(
List<VRMLModel> VRMLList,
Transform3D[] transList,
Transform3D globalTrans)
{
 
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
Gl.glLoadIdentity();               
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
    vrml.GenerateSurfaceNormalsNeighboursBFS();

    // Begin drawing the triangels
    Gl.glBegin(Gl.GL_TRIANGLES);
    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);
        n.normalize();
        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);
        n.normalize();
        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);
        n.normalize();
        Gl.glNormal3f(n.x, n.y, n.z);
        Gl.glVertex3f(v3.x, v3.y, v3.z);

        }
    Gl.glEnd();
    }
Gl.glPopMatrix();
Gl.glEndList();
Gl.glFlush();
simpleOpenGlControl.Refresh();
}

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 .

Leon.