You need to
1. Set up a device
internal void initGraphics()
{
// Set our presentation parameters, set up the Direct3D device
presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.DeviceWindow = this.portalPanel; //the subclass of Form you
are drawing on .
//set up z buffer so that near objects obscure far objects.
//If graphics card does not support we are in trouble here.
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
// Store the default adapter
int adapterOrdinal = Manager.Adapters.Default.Adapter;
CreateFlags flags = CreateFlags.SoftwareVertexProcessing;
Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);
// Do we support hardware vertex processing?
if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
// Replace the software vertex processing
flags = CreateFlags.HardwareVertexProcessing;
// Do we support a pure device?
if (caps.DeviceCaps.SupportsPureDevice)
flags |= CreateFlags.PureDevice;
flags = CreateFlags.HardwareVertexProcessing; //better be there...
try
{
// Create our device
device = new Device(adapterOrdinal, DeviceType.Hardware,
this.portalPanel, flags, presentParams);
}
catch
{
if (device != null)
device.Dispose();
MessageBox.Show("unable to create device");
clearFlags = ClearFlags.Target;
presentParams.EnableAutoDepthStencil = false;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
}
}
2. Set up a buffer that contains triangles whose vertices are on the
surface. If the triangles are small enough you get a reasonable
approximation to the surface. Alternatively, you can just render points on
the surface (but this will not give you lighting effects). You can render a
list of lines as well.
device.BetginScene();
device.DrawUserPrimitives(PrimitiveType.TriangleList, triangleCount,
renderBuffer);
device.EndScene();
device.Present();
where renderBuffer contains your list of triangles.
You also need code to set the position of the camera, the position of the
lights, and to set up matrices for transforming from object space to model
space to world coordinates. All in all in might be 30-40 lines of code.
Something like:
device.RenderState.Ambient = Color.DarkBlue;device.RenderState.CullMode =
Cull.CounterClockwise;
device.RenderState.Lighting = true;
device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.LightBlue;
device.Lights[0].Direction = new Vector3(0, 0, -1);
device.Lights[0].Commit();
device.Lights[0].Enabled = true;
device.Transform.World = worldTransform;
device.Transform.Projection =
Matrix.PerspectiveFovLH(camera.fieldOfView, camera.aspectRatio,
camera.nearPlane, camera.farPlane);
device.Transform.View =
Matrix.LookAtLH(camera.positionV, camera.targetPosition,
camera.up);
I recommend the book "Managed DirectX 9", byTom Miller which has many
examples. Reading the documentation for the above mentioned functions (in
the DirectX 9 SDK) will help as well.