Sign in to follow this  

Binding Managed DirectX device to a Panel

Recommended Posts

I am creatint an animal simulation system that displays a terrain and the animals on it. I have tested the terrain builder with a form that the device renders to a panel. Everything works perfect. I try putting the methods into my main form and all the panel displays is the ccleared background. I know that it is entering the Paint event method but I have no idea why it isnt displaying my terrain. Here is what I think is the relevant code. If more is needed I will gladly post. static void Main() { using(SimulationForm simForm = new SimulationForm()) { simForm.InitializeDevice(); simForm.InitializeLighting(); simForm.InitializeCamera(); simForm.InitializeTerrain(); Application.Run(simForm); } } private void InitializeDevice() { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; device = new Device(0, DeviceType.Hardware, this.dxPanel, CreateFlags.HardwareVertexProcessing, presentParams); } private void dxPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, xPanel.Width / dxPanel.Height, 1f, 10000f); device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); device.BeginScene(); device.Transform.World = Matrix.Scaling(1,1,1);(I just have this in here for terrain modification) tg.RenderTerrain(); device.Transform.World = Matrix.Identity;(I am not sure if DirectX resets world matrix everytime) device.EndScene(); device.Present(); this.Invalidate(); }

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this