Sign in to follow this  
moonshot

Drawing a simple rectangle

Recommended Posts

I'm doing a 2D game and I'm using textured quads. Everything is great, I'm drawing what I need to. However, I need to draw a very tall(600pixel) rectangle. I could draw a 32x32 graphic down the screen, but I thought maybe just drawing a rect would be easier. Does DirectX have a simple DrawRect type function? Do I need to use the GDI and setup a pen and all the crap? I'm only drawing one.

Share this post


Link to post
Share on other sites
Are you using orthogonal, XYZ_RHW, or D3DXSprites? I don't recommend trying to mix GDI and D3D. You could use line segments instead of triangles for the primitive of choice, but they are considerably slower and (I think) only one pixel wide, so don't use very many.

What I did is create a vertex buffer, then draw 4 rectangles that are only X pixels wide (each rectangle is the border of your big rectangle). Set the vertex color to the color you want the borders to be. This is assuming you want an empty rectangle.

Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by moonshot
Does DirectX have a simple DrawRect type function? Do I need to use the GDI and setup a pen and all the crap? I'm only drawing one.


Not as simple as a DrawRect function. But look into the ID3DXSprite interface. You juet need to create it with D3DXCreateSprite, then call sprite->Begin(); sprite->Draw(); sprite->End(); and you'll get your image on screen.

Share this post


Link to post
Share on other sites
or just make a vertex class and make your own draw rect function, it'd be rediculusly simple if you already have a... wait you already have a draw rect function... just change the vertex format so there is diffuse color and no uv coords, if what you want is just an untextured 2d rectangle.

Share this post


Link to post
Share on other sites
moonshot,
As an alternative to the ideas suggested, i would suggest the ID3DXLine interface. Look it up in the SDK documentation, it basically allows drawing of lines, and creating a DrawRect functions would be easy.

Aface

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this