Sign in to follow this  
spiffycrony

Rubber band polygon in directx8

Recommended Posts

I am trying to draw a rubber band polygon i.e when we click the screen for the first time, i need to draw a line from that point say p1 to the current position of the mouse, so that when we keep moving the mouse the line should follow the mouse. Next when we click the second point say p2, draw a line l1 between p1 & p2, then a line from p2 to the current mouse position. Finally when we say do a right click the last point pn and p1 should be connected with a line creating a polygon. I think there is no direct function in directx8 to draw a line. No clue after searching a lot. Any clue of how to do this?

Share this post


Link to post
Share on other sites
And you can always use a very thin textured quad instead of an 'actual' line. This gives you easier control over color, opacity, blend mode, etc. Plus you could use things like a simple gradient band texture to make lines more interesting.

I would be interested to hear what kind of vertex buffer people would recommend for this scenario... I would probably use dynamic if the vertices needed to constantly change smoothly in response to mouse movement.

Share this post


Link to post
Share on other sites
Quote:
Original post by MasterWorks
And you can always use a very thin textured quad instead of an 'actual' line. This gives you easier control over color, opacity, blend mode, etc. Plus you could use things like a simple gradient band texture to make lines more interesting.

I figured that lines use the same rasteriser as triangles in D3D, so the blending options would be the same.

Using quads seems like a good idea if you'd like the line's thickness to depend in its view-space z-distance, but I see no benefit if the lines are to be of uniform thickness in screen space: getting the quad width right would be a bit of a pain, as you'd need to scale the billboard's thickness according to the distance from the camera.

Admiral

Share this post


Link to post
Share on other sites
@TheAdmiral:

I had the same doubts when I first read about this quad idea a while ago, but it seems that modern game-oriented GPU's can actually render triangles more efficiently than lines. Pricy CAD-oriented GPUs like the Quadro reportedly focus more on that, so I doubt this is going to change soon.

The main reason to use quads for line segments however would be getting any control over the line's thickness. By default, lines are only 1 pixel thick and I don't recall there's an easy (or any?) way to change them, so it's going to be hard to create any interesting effect with them, especially at high resolutions.

As for the implementation, you can always use pretranformed coordinates to define your quads, so you don't have to worry about the zrange at all. The blend mode might not make the difference, but the ability to properly texture a line is extremely useful, as MasterWorks already pointed out.

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