Jump to content
  • Advertisement
Sign in to follow this  
jor1980

Substitute OnPaint c#

This topic is 2857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i have the next problem:

i have created in a .cs file a nameSpace called viewer3D and in its class viewer i have created all the necessary funtions to display meshes with SlimDX.

Now i am using this namespace from a form, and i want to use a panel control from this form to display the 3d view, so i need to change the OnPaint method of the panel for the OnPaint function that i have created in the class viewer

how can i make this?Here is the Onpaint functions of my viewer class:


public void OnPaint(Control objeto)
{
myDevice.SetRenderState(RenderState.CullMode, true);
myDevice.SetRenderState(RenderState.FillMode, FillMode.Solid);
myDevice.SetRenderState(RenderState.Lighting, false);

myDevice.Clear(ClearFlags.Target | ClearFlags.ZBuffer, new Color4(Color.Gray), 1, 0);
myDevice.MultiplyTransform(TransformState.Projection,Matrix.PerspectiveFovLH(3.1415F/4,objeto.Width/objeto.Height,1.0F,500000F));
myDevice.MultiplyTransform(TransformState.View,Matrix.LookAtLH(new Vector3(0,170,70),new Vector3(0,170,0),new Vector3(0,1,0)));


myDevice.BeginScene();

myDevice.VertexFormat = VertexFormat.Position | VertexFormat.Texture1;

for (int i = 0; i < slimdxMeshList.Count; i++)
{
slimdxMeshList.DrawSubset(0);
}

myDevice.EndScene();
myDevice.Present();
objeto.Invalidate();
}

Share this post


Link to post
Share on other sites
Advertisement
The IDirect3DDevice9::Present method has a parameter that let you to specify the window handle of the form you want it to draw on. Normally, you pass it NULL which means to tell the device to draw in the default window, but you can override it to draw somewhere else. That should let you draw with Direct3D anywhere.

I have no idea if the Panel object has its own hWnd property. If it does, just pass it that hWnd when you present and it should work. If the Panel object has no hWnd property of its own, it's because the panel is not "real" for Windows and its rendering is handled by WinForms, so pick the underlying WinForms component that has an hWnd property. In both cases, you have to adjust the viewport so it is properly scaled to the control.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!