Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted

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.

Posted
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 ;)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...