Pixels not occluding

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I'm trying to learn Managed DirectX by writing a simple little program that
displays two spheres. I then experiment by altering lighting, moving the
camera around, translating the spheres, etc. I seem to be having a problem
pixel occlusion that I can't find a solution to anywhere in the
documentation. Here's what I've done:

-I initialize the graphics as follows:

public void InitializeGraphics()
{
//Set the presentation parameters:
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;

//Now create the device:
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, presentParams);

//Set the lighting conditions:
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.White;
device.Lights[0].Direction = new Vector3(0,0,1.0f);
device.Lights[0].Commit();
device.Lights[0].Enabled = true;
}


-Then I set up my camera:

private void SetupCamera()
{
//Set the view transform:
device.Transform.View = Matrix.LookAtLH(new Vector3(0,0,-36.0f), new
Vector3(),
new Vector3(0,1,0));
//Set the projection transform:
device.Transform.Projection = Matrix.PerspectiveFovLH( (float)Math.PI/4,
(float)this.Width/(float)this.Height, 0.0f, 100.0f);
}


-I create two functions that create spheres with different properties :

private void DrawSphere1(float radius, float X, float Y, float Z)
{
//Create the sphere1 mesh:
Mesh mesh = Mesh.Sphere(device,radius,52,52);

//Apply the mesh material:
Material sphere1Material = new Material();
sphere1Material.Ambient = Color.Blue;
sphere1Material.Diffuse = Color.Blue;
device.Material = sphere1Material;

//Translate sphere1 to the XYZ coords arguments:
device.Transform.World = Matrix.Translation(X,Y,Z);

mesh.DrawSubset(0);
}

private void DrawSphere2(float radius, float X, float Y, float Z)
{
//Create the sphere2 mesh:
Mesh mesh = Mesh.Sphere(device,radius,52,52);

//Apply the mesh material:
Material sphere2Material = new Material();
sphere2Material.Ambient = Color.White;
sphere2Material.Diffuse = Color.White;
device.Material = sphere2Material;

//Translate the sphere to the XYZ coords:
device.Transform.World = Matrix.Translation(X,Y,Z);

mesh.DrawSubset(0);
}

-Finally in my paint event handler I have:

//Clear the device and display a solid color:
device.Clear(ClearFlags.Target |
ClearFlags.ZBuffer,System.Drawing.Color.CornflowerBlue, 1.0f, 0);

//Setup the camera:
this.SetupCamera();

//Draw the spheres:
device.BeginScene();
DrawSphere1(3.0f,0,0,0);
DrawSphere2(3.0f,1.5f,0,0);
device.EndScene();

device.Present();


When the spheres are drawn, they appear semitransparent i.e. I am able to
partially see one through the other. Shouldn't one be completely occluded?
I feel I might not be using "mesh.DrawSubset(...)" properly...is this the
case? As always, thanks in advance everyone!
.



Relevant Pages

  • Assigning different colors
    ... I have a bunch of gluSpheres that I randomly place in an environment. ... Now I want to do the following: spheres that are closer to the 'camera' should have a different color than those that are further away. ... spheres that are closest to the camera are assigned a red color and that color changes to green for spheres that are further away... ...
    (comp.graphics.api.opengl)
  • Re: Assigning different colors
    ... Andy V wrote: ... Now I want to do the following: spheres that are closer to the 'camera' should have a different color than those that are further away. ... spheres that are closest to the camera are assigned a red color and that color changes to green for spheres that are further away... ...
    (comp.graphics.api.opengl)
  • Re: Assigning different colors
    ... I have a bunch of gluSpheres that I randomly place in an environment. ... Now I want to do the following: spheres that are closer to the 'camera' should have a different color than those that are further away. ... spheres that are closest to the camera are assigned a red color and that color changes to green for spheres that are further away... ...
    (comp.graphics.api.opengl)