Jump to content
  • Advertisement
Sign in to follow this  
Ksingh30

DirectX C#

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

please help me I been getting this error for weeks, cant find out how to fix this.
CustomVertex.TransformedColored[] vertices=new CustomVertex.TransformedColored[3];
 
             vertices[0].Position = new Vector4(150f, 100f, 0f, 1f);
             vertices[0].Color = Color.Red.ToArgb();
             vertices[1].Position = new Vector4(this.Width/2+100f, 100f, 0f, 1f);
             vertices[1].Color = Color.Green.ToArgb();
             vertices[2].Position = new Vector4(250f, 300f, 0f, 1f);
             vertices[2].Color = Color.Yellow.ToArgb();

            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);

            device.BeginScene();
                Player1.Draw();
                           device.VertexFormat = CustomVertex.TransformedColored.Format;
             device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);
           
            device.EndScene();
           device.Present();
and I get this error when the code gets to this line. device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices); this is the error I get. An unhandled exception of type 'Microsoft.DirectX.Direct3D.InvalidCallException' occurred in Microsoft.DirectX.Direct3D.dll Additional information: Error in the application.

Share this post


Link to post
Share on other sites
Advertisement
I've had that kind of problem in the past.. it's a real pain, because probably it's somewhere else in your code that's the problem. Try commenting out Player1.Draw for starters.

I wrote this real quick, using your source code, and it works on my machine. Try starting up a new project, add Microsoft.DirectX and Microsoft.DirectX.Direct3D references and replace the form code with this to see if it works. Then you can take it and slowly make it look like your code in your other project. If you do it one line at a time and test it between each line, you should be able to narrow down the problem quickly.


public partial class Form1 : Form
{
Device device;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
PresentParameters p = new PresentParameters();

p.DeviceWindow = this;
p.EnableAutoDepthStencil =false;
p.BackBufferHeight = this.Height ;
p.BackBufferWidth = this.Width ;
p.BackBufferCount = 1;
p.BackBufferFormat = Format.Unknown;
p.Windowed = true;
p.PresentationInterval = PresentInterval.Immediate;
p.PresentFlag = PresentFlag.LockableBackBuffer;
p.SwapEffect = SwapEffect.Copy;

device = new Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware,
this.Handle, CreateFlags.SoftwareVertexProcessing,
p );

}

private void Form1_Paint(object sender, PaintEventArgs e)
{


CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[3];



vertices[0].Position = new Vector4(150f, 100f, 0f, 1f);

vertices[0].Color = Color.Red.ToArgb();

vertices[1].Position = new Vector4(this.Width / 2 + 100f, 100f, 0f, 1f);

vertices[1].Color = Color.Green.ToArgb();

vertices[2].Position = new Vector4(250f, 300f, 0f, 1f);

vertices[2].Color = Color.Yellow.ToArgb();



device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);



device.BeginScene();

//Player1.Draw();

device.VertexFormat = CustomVertex.TransformedColored.Format;

device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertices);



device.EndScene();

device.Present();


}
}


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!