Sign in to follow this  

2D Drawing using Client Coordinates

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

Hello, everyone: Of all the resources I've found on the Internet and through books, I've always noticed that they focus on 3D graphics and not 2D graphics. Now, I would like to draw some lines in the window, but I do not want the camera location to affect the size and quality of the lines. Also, my lines are dependent on the size of the window, so if the window is resized, the lines will reflect the change. Is it possible to specify -- in client coordinates -- a set of lines? I suppose one can equate this to GDI or GDI+. In GDI, you just use client coordinates to draw a line. I would use GDI, but the double-buffering problem becomes and issue. So, in all, I'm asking if it's possible to draw lines using the client coordinates of the window and not "space" coordinates of the camera, etc. Thank you, Trecius

Share this post


Link to post
Share on other sites
Unless you are going to draw lines as a sprite, you're going to have to draw the lines using 3D coding and doing the transform to screen coordinates.

I don't recall any current version of DX or XNA having any functions that that make it simple to draw lines in 2D space. Though there might be helper library function that might; Though I've always been told to avoid using them due to very poor performance from using them (Sloppily coded, etc).

Explicit 2D rendering was dropped from DirectX several versions ago, and you had to use the basics of 3D programming to draw 2D graphics on textured quads. XNA has been the first MS SDK in a while that has substantial support for drawing 2D graphics. But drawing points and lines are still restricted to doing them in 3D so far.

So the short answer is NO, we're just lucky to have sprite support in XNA so far.

Share this post


Link to post
Share on other sites
Assuming you're taking the Direct3D route, You could always spend the one-time investment of setting up an axis-aligned orthographic projection, hence turning the 3D environment into a pseudo-2D one. This is how many people take advantage of 3D acceleration for 2D games.

But I don't see why you can't just specify a D3DPT_LINELIST with a vertex-declaration that specifies transformed vertices. I've never seen it done, but I think it's kosher.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheAdmiral
But I don't see why you can't just specify a D3DPT_LINELIST with a vertex-declaration that specifies transformed vertices. I've never seen it done, but I think it's kosher.

I'm almost certain you can do this -- and you can certainly use screen coordinates as you see fit. It's pretty common to render a frame using more than one type of vertex declaration, so it shouldn't impact the rest of your project if you are doing 3D stuff also.

I would think that doing this with GDI or GDI+ in combination with DX is an absolutely terrible idea. DX can be annoying when it comes to 2D stuff but there's usually a better way than the brute force lock and modify pixels type solutions.

Also note that it is sometimes advised that you just use very thin quads (instead of lines) because of the additional control you get (and perhaps more universal driver support, although I can't confirm that.) Using quads you can texture your lines in unique ways. If you need more help maybe you could tell us what version of DX you're using, what your requirements are, etc.

Share this post


Link to post
Share on other sites
Quote:
Original post by MasterWorks
Also note that it is sometimes advised that you just use very thin quads (instead of lines) because of the additional control you get (and perhaps more universal driver support, although I can't confirm that).

I can't confirm this either, but I recall reading that appropriately thin quads can be significantly more performant than lines too, when taken over a wide sample of hardware.

Share this post


Link to post
Share on other sites

This topic is 3658 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.

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