Jump to content
  • Advertisement
Sign in to follow this  
Kryptus

DrawRectangle - Question

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

I'm putting together a small engine just to play around with in Managed DirectX 9 for C# 2005, but this whole concept applies to DX in general. I've made a class dedicated to the output of 2D graphics on the screen such as fonts and shapes. My draw rectangle subroutine is displayed below:
private CustomVertex.TransformedColored[] vRectangle = new CustomVertex.TransformedColored[5];

public void DrawRectangle(float Left, float Top, float Width, float Height, Color Colour)
        {
            vRectangle[0].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[0].Color = Colour.ToArgb();
            vRectangle[1].Position = new Vector4(Left + Width, Top, 1.0f, 1.0f); vRectangle[1].Color = Colour.ToArgb();
            vRectangle[2].Position = new Vector4(Left + Width, Top + Height, 1.0f, 1.0f); vRectangle[2].Color = Colour.ToArgb();
            vRectangle[3].Position = new Vector4(Left, Top + Height, 1.0f, 1.0f); vRectangle[3].Color = Colour.ToArgb();
            vRectangle[4].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[4].Color = Colour.ToArgb();

            SWGraphics.D3DDev.VertexFormat = CustomVertex.TransformedColored.Format;
            SWGraphics.D3DDev.DrawUserPrimitives(PrimitiveType.LineStrip, 4, vRectangle);
        }


What I want to ask is this: This sub can be called once, twice or even three times from the same variable and still render to the screen, except for the fact that everytime it's rendered is sets the position again. I'm concerned about any decrease in framerate or CPU/RAM usage. What happens? Is it wise to do it this way? I'll show a small example of how it's used: So this code will draw 4 rectangles.
public CScreen Screen = null;

Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);
Screen.DrawRectangle(Blah Blah);


I would prefer it as the above way instead of:
// This way would mean I can set up the size, colour, etc. before I render,
// possibly increasing framerate? This way is too long though.
public CScreen Screen1 = null;
public CScreen Screen2 = null;
public CScreen Screen3 = null;
public CScreen Screen4 = null;

Screen1.DrawRectangle(Blah Blah);
Screen2.DrawRectangle(Blah Blah);
Screen3.DrawRectangle(Blah Blah);
Screen4.DrawRectangle(Blah Blah);


How should I do it?

Share this post


Link to post
Share on other sites
Advertisement
I'll give this a shot.

Having multiple screens is a bit counter intuitive in this senario.

Try creating a CRectangle class.
This or something like it would go in the constructor

vRectangle[0].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[0].Color = Colour.ToArgb();
vRectangle[1].Position = new Vector4(Left + Width, Top, 1.0f, 1.0f); vRectangle[1].Color = Colour.ToArgb();
vRectangle[2].Position = new Vector4(Left + Width, Top + Height, 1.0f, 1.0f); vRectangle[2].Color = Colour.ToArgb();
vRectangle[3].Position = new Vector4(Left, Top + Height, 1.0f, 1.0f); vRectangle[3].Color = Colour.ToArgb();
vRectangle[4].Position = new Vector4(Left, Top, 1.0f, 1.0f); vRectangle[4].Color = Colour.ToArgb();


and CRectangle would contain an array CustomVertex.TransformedColored

Then change CScreen's DrawREctangle to something like:

public void DrawRectangle(CRectangle rectangle)
{
SWGraphics.D3DDev.VertexFormat = CustomVertex.TransformedColored.Format;
SWGraphics.D3DDev.DrawUserPrimitives(PrimitiveType.LineStrip, 4, rectangle.getVertices());
}



Note:By no means is the above syntatically correct. I'm a C++ programmer, not a C# programmer, but the same principles apply.

If any of this doesn't make sense, I'd be happy to brush up on my C# and post something more compilable.

Share this post


Link to post
Share on other sites
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!