2D Drawing using Client Coordinates

Started by
4 comments, last by Endurion 16 years, 4 months ago
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
Advertisement
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.
-------------------------------------------------------- What''s the difference between engineers and architects? Engineers build weapons; architects build targets. --------------------------------------------------------
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.
Ring3 Circus - Diary of a programmer, journal of a hacker.
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.
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.
Ring3 Circus - Diary of a programmer, journal of a hacker.
Just use pretransformed vertices, they are not affected by any matrices and lighting.

They can use screen coordinates, so any scaling to screen size must be done by yourself.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

This topic is closed to new replies.

Advertisement