Vankwysha Posted September 9, 2005 Posted September 9, 2005 I'm using VB.NET and Direct3D 9 to build my 2D game. I've been having trouble drawing primitive shapes, such as triangles, rectangles etc., as I do not want to use VertexBuffers and Device.DrawPrimitives. I found the Direct3D.Line class which makes it easy enough to draw polygons, but I haven't been successful in drawing a convincing circle. What I need is to be able to set the individual pixels on my screen so that I can use an equation to set the pixels in a circle. Is there some class or Direct3D.Device method that can make this easier? Any help is much appreciated. Quote
sgt_pinky Posted September 12, 2005 Posted September 12, 2005 Typically, 2D games are created using 'Sprites'. This is a texture, created from an image file, that is rendered straight to the device. Like: Dim xx As New Texture = TextureLoader.FromFile(drender, "C:\file.bmp") Dim yy As New Sprite(dRender) yy.Begin(SpriteFlags.AlphaBlending) yy.Draw2D( blah blah blah ) yy.End The "blah blah blah" contains information such as the x,y position on the screen that you want to draw the texture, rotation, etc. I just typed that code in then, so it's probably wrong - but you get the idea. So how I would draw a circle would be to use the GDI to draw a circle onto a New Bitmap, then create a texture out of the bitmap, and alpha blend it to the rendering device using a sprite. Also, you should draw as many textures onto one sprite as possible. It is much more efficient than rendering many sprites with one texture each. So you need to have a look at doing something like this: Dim uu As New Bitmap(100, 100, Imaging.PixelFormat.Format32bppArgb) Dim tt As Graphics = Graphics.FromImage(uu) tt.DrawString("hello", New Font("arial", 12, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red, 1, 1) But instead of DrawString, use DrawArc or whatever. Then create your texture from the image, then render a sprite with the image. Post code if you have problems. Quote
Vankwysha Posted September 13, 2005 Author Posted September 13, 2005 Generally speaking, is it faster to use a sprite object to draw textures or to use a textured quad (using a vertex buffer)? Quote
sgt_pinky Posted September 13, 2005 Posted September 13, 2005 Faster to draw a sprite, by far. Especially if you have a lot of very small vertex buffers. Then it is very inefficient to .SetStreamSource() only to render one 2 polys or something. Plus, you won't be able to achieve what you want anyway. For 2D, sprites all the way ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.