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