Original Post
I am simply rendering a teapot mesh using a window form with no device event handlers being managed. Works great, but the first minute I click into another window the cpu is at a 100 percent and xp is almost completely handicapped. I click back into the rendered window and bamb...everthing is back. I know this has to be something simple... Any ideas? using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace DSEdit { public partial class Form1 : Form { private Device GraphicDevice; //My objects private myTeapot centreTeapot; private float angle = 0; public Form1() { InitializeComponent(); } public void InitializeGraphics() { PresentParameters pp = new PresentParameters(); pp.Windowed = true; pp.BackBufferFormat = Format.X8R8G8B8; pp.SwapEffect = SwapEffect.Discard; pp.AutoDepthStencilFormat = DepthFormat.D16; pp.EnableAutoDepthStencil = true; GraphicDevice = new Device(0, DeviceType.Hardware, this.Handle, CreateFlags.SoftwareVertexProcessing, pp); GraphicDevice.RenderState.Lighting = true; GraphicDevice.RenderState.Ambient = Color.Gray; GraphicDevice.DeviceLost += new EventHandler(GraphicDevice_DeviceLost); GraphicDevice.DeviceReset += new EventHandler(GraphicDevice_DeviceReset); GraphicDevice.Disposing += new EventHandler(GraphicDevice_Disposing); GraphicDevice. } void GraphicDevice_Disposing(object sender, EventArgs e) { } void GraphicDevice_DeviceReset(object sender, EventArgs e) { } void GraphicDevice_DeviceLost(object sender, EventArgs e) { MessageBox.Show("device lost!"); } public void DisposeGraphics() { GraphicDevice.Dispose(); } public void SetupScene() { GraphicDevice.Transform.Projection = Matrix.PerspectiveFovLH(( float)Math.PI / 4, this.Width / this.Height, 1.0f, 500.0f); GraphicDevice.Transform.View = Matrix.LookAtLH( new Vector3(0, 0, -20), new Vector3(0, 0, 0), new Vector3(0, 1, 0)); GraphicDevice.RenderState.Lighting = true; GraphicDevice.Lights[0].Type = LightType.Directional; GraphicDevice.Lights[0].Position = new Vector3(-10, 0, -5); GraphicDevice.Lights[0].Attenuation1 = 0.1f; GraphicDevice.Lights[0].Range = 20.0f; GraphicDevice.Lights[0].Enabled = true; centreTeapot = new myTeapot(ref GraphicDevice); } public void Render() { GraphicDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer,Color.CornflowerBlue ,1,0); GraphicDevice.BeginScene(); //Get Cursor Position Point cursor = Point.Empty; cursor = this.PointToClient(Cursor.Position); if(cursor.X < 0) cursor.X = this.Width; if(cursor.Y < 0) cursor.Y = this.Height; //Centre Teapot GraphicDevice.Transform.World = Matrix.Identity; GraphicDevice.Transform.World = Matrix.Multiply(GraphicDevice.Transform.World, Matrix.Translation(0,-5,0)); centreTeapot.Intersect(cursor.X, cursor.Y, GraphicDevice.Viewport, GraphicDevice.Transform.Projection, GraphicDevice.Transform.View, GraphicDevice.Transform.World); centreTeapot.Render(ref GraphicDevice); angle += 1f; if (angle == 360.0f) { angle = 0; } GraphicDevice.EndScene(); GraphicDevice.Present(); } } class myTeapot { Mesh mesh; Material material; public myTeapot(ref Device dev) { mesh = Mesh.Teapot(dev); material = new Material(); material.Diffuse = Color.SeaGreen; material.Ambient = Color.SeaGreen; material.Specular = Color.SeaGreen; } public void Intersect(int X, int Y, Viewport viewport, Matrix projection, Matrix view, Matrix world) { Vector3 Nearcor; Vector3 Farcor; Nearcor = new Vector3(X, Y, 0); Nearcor = Vector3.Unproject(Nearcor, viewport, projection, view, world); Farcor = new Vector3(X, Y, 1); Farcor = Vector3.Unproject(Farcor, viewport, projection, view, world); Farcor.Normalize(); if (mesh.Intersect(Nearcor, Farcor)) { material.Diffuse = Color.Gold; material.Ambient = Color.Gold; material.Specular = Color.Gold; } else { material.Diffuse = Color.SeaGreen; material.Ambient = Color.SeaGreen; material.Specular = Color.SeaGreen; } } public void Render(ref Device dev) { dev.Material = material; mesh.DrawSubset(0) } } }