Rubber band polygon in directx8

Started by
3 comments, last by remigius 17 years ago
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?
Advertisement
I never actually worked with DX8, but under DX9 DrawPrimitiveUP(D3DPT_LINESTRIP, ...) (or D3DPT_LINELIST) should do the trick. I'd be fairly surprised if that was very different under DX8.
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.
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
Ring3 Circus - Diary of a programmer, journal of a hacker.
@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.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!

This topic is closed to new replies.

Advertisement