• Advertisement
Sign in to follow this  

[MDX] Vertex Buffer problem

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

Well sinse my move from C++ to C#, I have been reading some info on MDX and found a nice little site which gives some simple dx stuff. I moved from C++ to C# for DX because it seems so much nicer but I've come across my first problem.
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectX_App
{
    public class Game : System.Windows.Forms.Form
    {
        private Device device;
        private VertexBuffer vertices;
        protected bool InitializeGraphics()
        {
            PresentParameters pres = new PresentParameters();
            pres.Windowed = true;
            pres.SwapEffect = SwapEffect.Discard;
            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, pres);
            vertices = CreateVertexBuffer(device);
            return true;
        }
        protected void Render()
        {
            device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
            device.BeginScene();

            device.EndScene();
            device.Present();
        }
        protected VertexBuffer CreateVertexBuffer()
        {
            device.VertexFormat = CustomVertex.TransformedColored.Format;
            CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
            verts[0] = new CustomVertex.TransformedColored(this.Width / 2, this.Height / 4, 0.5F, 1, Color.Blue.ToArgb);
            verts[1] = new CustomVertex.TransformedColored(this.Width * 3 / 4, this.Height * 3 / 4, 0.5F, 1, Color.Green.ToArgb);
            verts[2] = new CustomVertex.TransformedColored(this.Width / 4, this.Height * 3 / 4, 0.5F, 1, Color.Red.ToArgb);
            VertexBuffer buf = new VertexBuffer(typeof(CustomVertex.TransformedColored), verts.Length, device, 0, CustomVertex.TransformedColored.Format, Pool.Default);
            GraphicsStream stm = buf.Lock(0, 0, 0);
            stm.Write(verts);
            buf.Unlock();

            return buf;
        }
        static void Main()
        {
            Game app = new Game();
            app.InitializeGraphics();
            app.Show();
            while (app.Created)
            {
                app.Render();
                Application.DoEvents();
            }
            //app.DisposeGraphics();
        }
    }
}


I'm not trying to render with it or anything, just get it set up but it is giving me the following errors.
Error	1	No overload for method 'CreateVertexBuffer' takes '1' arguments	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	18	24	DirectX Application1

Error	2	The best overloaded method match for 'Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored.TransformedColored(float, float, float, float, int)' has some invalid arguments	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	33	24	DirectX Application1

Error	3	Argument '5': cannot convert from 'method group' to 'int'	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	33	102	DirectX Application1

Error	4	The best overloaded method match for 'Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored.TransformedColored(float, float, float, float, int)' has some invalid arguments	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	34	24	DirectX Application1

Error	5	Argument '5': cannot convert from 'method group' to 'int'	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	34	110	DirectX Application1

Error	6	The best overloaded method match for 'Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored.TransformedColored(float, float, float, float, int)' has some invalid arguments	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	35	24	DirectX Application1

Error	7	Argument '5': cannot convert from 'method group' to 'int'	C:\Documents and Settings\HP_Administrator\My Documents\Visual Studio Projects\GameEngine\DirectX Application\DirectX Application1\Program.cs	35	106	DirectX Application1

Regards, Mike

Share this post


Link to post
Share on other sites
Advertisement
Pay attention to your signatures.

your CreateVertexBuffer() does not take any arguments -- if you try to pass it one it will not compile.

CustomVertex.TransformedColored takes four floats followed by an int. It may not be entirely obvious, but you are doing integer operations in the arguments to your new calls. Cast your parameters to floats -- you probably want to do this before you do your division or you will get unexpected results.

Hope this helps.

Share this post


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

  • Advertisement