Jump to content
  • Advertisement
Sign in to follow this  

[.net] MDX - drawing stuff inside a panel control.

This topic is 4860 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

I've decided to give MDX a serious go, and for my first project, I'm making a terrain visualizer kind of thing. The main panel will have the terrain rendered in and the other controls will control how the terrain is generated. Now I got d3d initialized, and I'm clearing the panel and *trying* to render a triangle in the panel. Problem is that it doesn't show. And I can't gifure out why, so any help would be appreciated. Here're some code snippets:
// TerrainPanel is a panel control object
Device = new D3d.Device( 0, D3d.DeviceType.Hardware, TerrainPanel, 
                D3d.CreateFlags.SoftwareVertexProcessing, PresentParams );

// and this is my render function that I call in the panels OnPaint method
void Render()
    if( Device == null )

    Device.Transform.Projection = Dx.Matrix.PerspectiveFovLH( 
        (float)Math.PI / 4.0f, 
        TerrainPanel.Width / TerrainPanel.Height, 

    Device.Transform.View = Dx.Matrix.LookAtLH(
        new Dx.Vector3(0, 0, 5.0f), 
        new Dx.Vector3(),
        new Dx.Vector3(0,1,0));

    Device.Transform.World = Dx.Matrix.Identity;

    Device.RenderState.Lighting = false;
    Device.RenderState.CullMode = D3d.Cull.None;

        D3d.ClearFlags.Target | D3d.ClearFlags.ZBuffer, 

    D3d.CustomVertex.PositionColored[] verts = new D3d.CustomVertex.PositionColored[3];
    verts[0].Position = new Dx.Vector3(0.0f, 1.0f, 1.0f);
    verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
    verts[1].Position = new Dx.Vector3(-1.0f, -1.0f, 1.0f);
    verts[1].Color = System.Drawing.Color.Black.ToArgb();
    verts[2].Position = new Dx.Vector3(1.0f, -1.0f, 1.0f);
    verts[2].Color = System.Drawing.Color.Purple.ToArgb();

    Device.VertexFormat = D3d.CustomVertex.PositionColored.Format;
    Device.DrawUserPrimitives( D3d.PrimitiveType.TriangleList, 1, verts );



Share this post

Link to post
Share on other sites
Could it be that you have 1.0f as the znear clipping plane but the vertices of the triangle is even nearer, i.e. -1.0f?

To solve this, just set the znear to -10.0f or something, or move the triangle further "back".

Share this post

Link to post
Share on other sites
But the triangle's Z is not -1, it's +1. Either way, I've tried it with a lot of values. THe following should work, but it doesnt:

camera: pos( 0, 0, -5 )
camera: look( 0, 0, 0 )

znear: 1.0f
zfar: 100.0f

triangle: zvalue: 1

Is the setup needed to render into a control correct? It seems just too simple, maybe I'm forgetting to do something?

Share this post

Link to post
Share on other sites
Does it work if you set the triangle at 2.0f instead?

Now it is precisly in the plane of the near clipping plane, and maybe there's some rounding off error?

Share this post

Link to post
Share on other sites
I noticed that you are using the onPaint method as your rendering loop.

Have you added the necessary code to do this? At the end of your onPaint method you need to invalidate the form by calling this.Invalidate();

Secondly, did you remember to set your control style? In the Form's constructor make sure you have the following method call:

this.Setstyle(Controlstyles.AllPaintingInWmPaint | Controlstyles.Opaque, true);

Hope this helps.

Share this post

Link to post
Share on other sites
I can't add the .invalidate method because my form crashes. But It should still show the triangle. It's not animated or anything so it doesnt matter if it's drawn once. I just want to render into a control successfully before I worry about the other things.

I created a new application and instead of rendering into a panel control I rendered to the entire window and everything worked fine. Triangle showed up with no problems. So I'm assuming that there's something wrong with the method I'm using to render into a control.

I'm figuring either I need to create a custom control, or I'm missing a step or two. Can anyone help me?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!