Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Doddler

Drawing a line in DD with C++

This topic is 6916 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! This is kinda embarassing... I''ve been working with D3D for a while now, and now i''ve run into such a simple problem. I''m trying to make a map editor for my game in direct draw and, I wanted to draw lines and grids, etc. Anyways, I''ve searched the SDK doccumentaition for a long time, and I''ve found nothing dealing with drawing a line with DirectDraw. I found drawing a line in DirectDraw for VB, but not for C++. If any one thinks they can help me, any help would be greatly apreciated. -Doddler

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Sorry, but there is no such thing as drawing a line in DirectDraw, as the api itself goes. If you''re going to draw a line, you''re going to have to lock the surface, keep an eye on what color depth you''re in and remember all those fun special caveats about width vs. pitch, and draw the line yourself. DirectDraw doesn''t have ANY primitives implemented (circle, point, etc.). The only thing you can do with it is colored rectangles and bitmap operations. Do a lookup on Brenshams(sp?) Algorithm for the best line algo to date, it shouldn''t be too hard to find.

Share this post


Link to post
Share on other sites
There are really only three ways to go with this, that I can think of.

1. Use a gdi function to do it (it has been awhile since I have used the gdi to draw anything other than a dialog box so I don''t remember exactly how)

2. Use someone''s 2d library, there are a few I have seen that work with ddraw and support lines.

3. Use direct surface access (lock the surface and write directly to it) to draw your own, try looking up Breshenham''s (Hope I spelled that right) line drawing algorithm. Another is the Run-slice algorithm, this one being the faster of the two algorithm''s.

-Omalacon

Share this post


Link to post
Share on other sites
For all line-drawing algorithms (the ones you might want are run-slice and Wu), see the Dr. Dobbs Journal articles of Michael Abrash (floating around the net) - they''re probably the best optimized. Also, D3D can draw lines (sometimes in HW).

Share this post


Link to post
Share on other sites
Well, I know quite a bit of D3D... I''m just not sure how I would use it to draw an accurate 2D grid... I beleve OpenGL has 2D vertex coords, but I''m not too sure about D3D. The thing is, I wan''t the grid you draw on to be accurate, to be able to create walls, and other things. I''ll look into Breshenham''s line drawing algorithm, but D3D would be more flexible for what I''m doing (creating a basic, 3D level). If anyone knows how to do this with D3D, I''d like to know. By the way, why does directX for VB support line drawing functions, where as directX for C++ doesn''t?

Anyways, thank''s for the help!

-Doddler

Share this post


Link to post
Share on other sites
Why not use pre transformed vertices in D3D. That way you specify the pixel positions of your vertices and if you set D3D to draw lines you should get exactly what you want, without having to lock the framebuffers.


Regards,
Ralph Potter
ralph.potter@digital-magi.com, http://www.digital-magi.com

Share this post


Link to post
Share on other sites
I think that pre-transformed vertexes would be best, but how would I get them to match up to the X and Y coords on the screen?

Share this post


Link to post
Share on other sites
To specify vertices in screen coordinates, make your projection matrix an orthographic projection, set your viewport to the window dimensions (or whatever) and set your other transformation matrices (world, etc.) to identity. I''m not sure how to do this in Direct3D, if you were using OpenGL then I''d be more of a help, but...

-Liquid

Share this post


Link to post
Share on other sites
Doddler,

I''ve been through this already.

Check out:
http://www.gamedev.net/community/forums/topic.asp?topic_id=13387&forum_id=10&Topic_Title=2D+on+3D&forum_title=DirectX%2FOpenGL%2FGlide%2FGenesis3D&M=False&S=True

Liquid,

Since the vertices are already transformed, you do not need
to use projections or transformation matrices. You just
need to setup a viewport.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!