Sign in to follow this  

How to draw lines like that ?

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

http://img269.imageshack.us/img269/2134/thrust.jpg I really like the graphics of Thrust Deluxe and I wonder how best I could draw the same kind of lines ? I can see they have these properties: - anti aliased - color gradient along the line - the line junctions are brighter as if the line colors are added together - there's a glow around the line which is added too So, 1) Can I do it with GDI+ ? as I want to write a C# 2D application 2) If not, how best could I do it in DirectX ? What kind of primitive (triangles or line) ? And which mode or type of shader to use ? Thanks !

Share this post


Link to post
Share on other sites
Based on the brightening at the junctions, my guess is that the glow isn't postprocessing, but rather based on additive blending of billboarded, pre-bloomed line textures multiplied by the line color. I'm not really familiar with the capabilities of GDI+, but Direct3D can do it easily. Your primitives would be rectangles, with per-vertex colors modulating the texture.

Share this post


Link to post
Share on other sites
Quote:
Original post by vlad2048
So,
1) Can I do it with GDI+ ?
as I want to write a C# 2D application


You could achieve this in GDI+ using GraphicsPath to make the shape of the glow, like a flattened capsule. The gradient effect can be achieved using LinearGradientBrush (I know these are the c++ links, but I'm not sure where the C# equivalent docs are).

However this would probably be a heck of a lot easier with DirectX.

Share this post


Link to post
Share on other sites
Thanks a lot guys !

Sneftel:
I think you're right. But after trying there's a little subtelety. A 1D texture to draw the line is perfect, but I need to "cap" the line with half a disc on each side. So 3 billboards: 1 line + 2 caps. (And actually the caps don't "mesh" too well for successive lines, I think I'd be better off just drawing one single full disc for each line junctions)

_moagstar_:
I'm going to look into that right now. I'd rather use GDI+ if it's possible. I will report back

Share this post


Link to post
Share on other sites
_moagstar_:
It seems the LinearGradientBrush only does Linear gradient.
But my line 1D pattern is not linear. It's very bright in the center (4/5 pixels) and then very dim to black outside. Nothing proportional there.
Do you still think it's possible with GDI+. And will the additive blending be possible with these lines ?

Share this post


Link to post
Share on other sites
If you're not updating the image every frame and can be bothered to spend 10 minutes writing your own GDI drawing code (and consequently not worry about any API's), you can always write your own glow filter (draw lines using GDI+ or whatnot, or write your own antialiased line drawing code, or check online for source code on how to do that; for each line segment create a bounding box which extends N pixels away from the line in each direction, for each pixel in the bounding box calculate distance to line segment and modulate alpha by distance, do additive blend using max() as the term to decide whether to retain the source glow value or use the new one - meaning you won't get banding at the joints that Sneftel mentioned).

Share this post


Link to post
Share on other sites
Well I want to be able to draw lines of different sizes, so I can't possibly use one single texture for all of them. Or the cap wouldn't be circular but ellipse shaped.

Share this post


Link to post
Share on other sites

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