Jump to content
  • Advertisement
Sign in to follow this  
Delryn

[MDX] Drawing Sprites and VertexBuffer-Information

This topic is 4468 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, it's me again. Im trying to write a simple framework for 2D-Games. At the moment my render-loop lokes like this:
        public void BeginScene()
        {
            device.Clear(ClearFlags.Target, System.Drawing.Color.CornflowerBlue, 1.0f, 0);
            device.BeginScene();
            drawingSprite.Begin(SpriteFlags.AlphaBlend);
        }

// Im now drawing Sprites in my application and call after this:

        public void EndScene()
        {
            drawingSprite.Flush();
            drawingSprite.End();
            device.EndScene();
            device.Present();
        }

I orientated myself on the msdn where I found this:
Quote:
Typically, the application first calls Sprite.Begin, which allows control over the device render state, alpha blending, and sprite transformation and sorting. Then, for each sprite to display, the application calls Sprite.Draw, which can be called repeatedly to store any number of sprites. To display the batched sprites to the device, the application calls Sprite.End or Sprite.Flush.
Seems to me that you should only call "Sprite.Begin()" one time when you render. And this works really fine, I can draw over 2000 Sprites with my old pc without problems. But now to my problem, beside only drawing Sprites I need functions like "DrawLine" or "DrawRect". I realised this with the vertexbuffer:
public void DrawLine(int x, int y, int zx, int zy)
        {
            CustomVertex.PositionColored[] vert = new CustomVertex.PositionColored[2];
            
            vert[0].X = x;
            vert[0].Y = y;
            vert[0].Z = 1;
            vert[0].Color = System.Drawing.Color.Green.ToArgb();

            vert[1].X = zx;
            vert[1].Y = zy;
            vert[1].Z = 1;
            vert[1].Color = System.Drawing.Color.Green.ToArgb();


            
            vertexBuffer.SetData(vert, 0, LockFlags.None);
            device.DrawPrimitives(PrimitiveType.LineList, 0, 1);
        }

This function can be called between my BeginScene() und EndScene() methods. But it doesn't make any difference where you call the DrawLine()-method, the sprites are always in front of my lines. I placed DrawLine() in the EndScene()-method:
        public void EndScene()
        {
            DrawLine(600, 10, 600, 700);
            drawingSprite.Flush();
            drawingSprite.End();
            device.EndScene();
            device.Present();
        }

But the damn Sprites are always in front of my lines, I cant explain myself why?! And has anybody an idea how I could draw bolt-lines or to write a better "DrawLine()"-Method? Thank you

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!