Jump to content
  • Advertisement
Sign in to follow this  
jdub

[SlimDX]What is wrong with this code?

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

When I try to render these 3 vertices I get an INVALID_CALL error. What could be wrong?
using System.Windows.Forms;
using SlimDX.Direct3D9;
using SlimDX;
using System.Drawing;
using Microsoft.Win32;
using System.Runtime.InteropServices;

namespace D3DExperiment
{

    [StructLayout(LayoutKind.Sequential)]
    public struct TransformedColoredVertex
    {
        public Vector4 Position;
        public SlimDX.Color4 color;
    }

    class BZWindow : Form
    {
        
        Device device;
        Direct3D d3d;
        TransformedColoredVertex[] vertices = new TransformedColoredVertex[3];

        private void CreateDevice()
        {
            
            d3d = new Direct3D ();

            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Flip;
            presentParams.BackBufferFormat = Format.A8R8G8B8;
            presentParams.BackBufferHeight = 600;
            presentParams.BackBufferWidth = 800;
            presentParams.DeviceWindowHandle = this.Handle;


            vertices[0].color = new Color4(Color.Tan.ToArgb());
            vertices[0].Position = new Vector4(new Vector3(20 , 20 , 20 ) , 1);

            vertices[1].color = new Color4(Color.Tan.ToArgb());
            vertices[1].Position = new Vector4(new Vector3(25 , 25 , 25 ) , 1);

            vertices[2].color = new Color4(Color.Tan.ToArgb());
            vertices[2].Position = new Vector4(new Vector3(345 , 200 , 200 ) , 1);

            device = new Device ( d3d , 0, DeviceType.Reference, this.Handle , CreateFlags.SoftwareVertexProcessing ,presentParams );
            
        }

        public BZWindow()
        {
        }
        

        protected override void OnPaint(PaintEventArgs e)
        {
            device.BeginScene ();
                                                                    //zdepth and stencil
            device.Clear ( ClearFlags.Target, new Color4(Color.Red) , 1 , 0 );
            device.DrawUserPrimitives<TransformedColoredVertex> ( PrimitiveType.TriangleList, 1, 3, this.vertices );

            device.EndScene ();

            
            device.Present ();
        }

        static void Main()
        {
            using (BZWindow window = new BZWindow())
            {
                window.CreateDevice ();
                Application.Run ( window );
            }
        }
    }
}


[Edited by - jdub on September 17, 2008 10:25:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
It doesn't look like you've set a VertexDeclaration or VertexFormat anywhere.

Also, on a side note, your application is rather malformed. It will only draw when you get paint messages, which can come whenever Windows feels like sending them. Take a look at the MiniTri sample that comes with SlimDX to see the preferred method of rendering a simple triangle.

Share this post


Link to post
Share on other sites
Also, you should use the D3D debug runtimes (they come with the SDK). In this case specifically, the debug runtime would have told you that you were missing a vertex declaration/format. The error messages provided by Direct3D aren't exactly brimming with information about the cause of errors, and this is where the debug runtime can help you immensely.

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!