Tom Miller DirectX Teapot
Tuesday, May 30, 2006, 01:32 PM
If you have the book
Beginning 3D Game Programming, by Tom Miller, you may have noticed that the Teapot example in the second chapter doesn't compile. This problem is mentioned by some commenters on his
blog, but Tom never comments directly on the problem, and the suggested solution given by another person only partially solves the problem, showing the teapot, but not properly lighting it. To fix the code in the book, change this bit here:
device = e.Device();
teapotMesh = Mesh.Teapot(device);
teapotMaterial = new Material();
teapotMaterial.DiffuseColor = new ColorValue(1.0f, 1.0f, 1.0f, 1.0f);
to this:
this.teapotMesh = Mesh.Teapot(e.Device);
this.teapotMaterial = new Material();
this.teapotMaterial.DiffuseColor = new ColorValue(1.0f, 1.0f, 1.0f, 1.0f);
and change all of these:
device.Lights[0]...
to this:
e.Device.Lights[0]...
and then in the last block of code that Tom has you add to OnFrameRender, add this line prior to the teapotMesh.DrawSubset(0); line:
device.Material = this.teapotMaterial;
That's it, happy coding.
Tom