Jump to content
  • Advertisement
Sign in to follow this  
jdub

[SlimDX] Why won't this program draw anything

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

This program compiles fine, and clears the screen to blue but doesn't draw my triangles. I compared it almost line to line with the MiniTri sample and can't find anything wrong with it.
[StructLayout(LayoutKind.Sequential)]
    struct TransformedColoredVertex
    {
        public Vector4 Position;
        public int color;
    }

    static class Program
    {
        static Direct3D d3d;
        static Device d3dDevice;
        static VertexBuffer triangleBuff;


        [DllImport ( "User32.dll" )]
        [return: MarshalAs ( UnmanagedType.Bool )]
        static extern bool PeekMessage(out Message msg, IntPtr hWnd, uint messageFilterMin, uint messageFilterMax, uint flags);

        

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Form form = new Form ();
            form.ClientSize = new Size ( 600, 600 );
            form.Text = "Test Form";
            form.Visible = true;

            d3d = new Direct3D ();
            
            PresentParameters PresentParams = new PresentParameters ();
            PresentParams.BackBufferHeight = form.ClientRectangle.Height;
            PresentParams.BackBufferWidth = form.ClientRectangle.Width;
            PresentParams.DeviceWindowHandle = form.Handle;
            PresentParams.SwapEffect = SwapEffect.Discard;
            PresentParams.Windowed = true;
            
            d3dDevice = new Device ( d3d, 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, PresentParams );

            triangleBuff = new VertexBuffer ( d3dDevice, 20 * 3, Usage.WriteOnly, VertexFormat.None, Pool.Managed );

            DataStream stream = triangleBuff.Lock ( 0, 0, LockFlags.None );

            TransformedColoredVertex[] triVerts = new TransformedColoredVertex[3];
            triVerts[0].color = Color.Black.ToArgb();
            triVerts[0].Position = new Vector4 ( 400.0f, 100.0f, 0.5f, 1.0f );
            triVerts[1].color = Color.Blue.ToArgb ();
            triVerts[1].Position = new Vector4 ( 400.0f, 400.0f, 0.5f, 1.0f );
            triVerts[2].color = Color.Red.ToArgb ();
            triVerts[2].Position = new Vector4 ( 400.0f, 100.0f, 0.5f, 1.0f );

            stream.WriteRange ( triVerts );
            triangleBuff.Unlock ();

            Application.Idle += new EventHandler(Program.OnIdle);

            Application.Run (form);
            
            d3dDevice.Dispose ();
            d3d.Dispose ();
            form.Dispose ();
        }

        public static void OnIdle( object obj, EventArgs eventArgs)
        {
            Message msg;
            
            while (!PeekMessage ( out msg, IntPtr.Zero, 0, 0, 0 ))
            {

                d3dDevice.Clear ( ClearFlags.Target | ClearFlags.ZBuffer,  Color.Blue.ToArgb(), 1.0f, 0 );
                d3dDevice.BeginScene ();

                d3dDevice.SetStreamSource ( 0, triangleBuff, 0, 20 );
                d3dDevice.VertexFormat = VertexFormat.PositionRhw | VertexFormat.Diffuse  ;
                d3dDevice.DrawPrimitives ( PrimitiveType.TriangleList, 0, 1);

                d3dDevice.EndScene ();
                d3dDevice.Present ();
            }
        }
    }

Share this post


Link to post
Share on other sites
Advertisement
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!