PDA

View Full Version : Rendering complex lines



jcgp
03-09-2006, 11:27 AM
Is there a obvious way to render double/triple lines in OpenGL? glLineStipple allows line definition in the longitudinal direction only...

Drawing two different lines side by side on 3D space does not work very well. I really want to render two lines at pixel level. The code below does this, first draw the full line and then overwrite with a thinner line, with the background color. Among other drawbacks, this needs the background color. Is there a simpler way of achieving this pixel-level double line effect?

This is usefull for example to render double and triple chemical bonds.

Thanks,
Carlos

glColor3fv (color_white);

glLineWidth (3);
glBegin (GL_LINES);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 0.0, 1.0);
glEnd ();

glColor3fv (color_black);

glLineWidth (1);
glBegin (GL_LINES);
glVertex3f (0.0, 0.0, 0.0);
glVertex3f (0.0, 0.0, 1.0);
glEnd ();

03-09-2006, 01:12 PM
Drawing two different lines side by side on 3D space does not work very well.Why not? You can use arbitrary widths and separation for each. You can look at line/full-scene anti-aliasing to smooth things out a bit, if that's what's bugging you.

You can render lines as quads, perhaps even textured.

jcgp
03-09-2006, 02:39 PM
It really depends of what you want to achieve.

In my case, I need this to represent double/triple chemical bonds. iF I use two real lines, side by side, when I rotate the molecule 90 degrees both lines will be in the same plane, normal to the screen, and the bond looks as a single bond. In general, depending of the rotation, some bonds will look as double and some will lokk as single bonds, quite disturbing. Rendering directly on 2D screen means the bonds always look as double lines, as expected.

Another mildly inconvenient effect is, when your molecule is closer and closer, the two lines naturally will move apart from each other, as they are getting closer. Rendering the bond directly on
pixel 2D space, they have always the same size, which is much better for analysis.

In this case, too much realism is bad. Anyway, getting the background color with

glGetFloatv (GL_COLOR_CLEAR_VALUE, background);

helps to decrease argument passing and simplifies my code. And the behaviour is just fine. I was just wondering if OpenGL does not have a mechanism to define line patterns, normal to the line direction...

For example, how can I render a line from point xyz1 to point xyz2 in 3D space, with this pattern?

/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_

jcgp
03-09-2006, 02:41 PM
It really depends of what you want to achieve.

In my case, I need this to represent double/triple chemical bonds. iF I use two real lines, side by side, when I rotate the molecule 90 degrees both lines will be in the same plane, normal to the screen, and the bond looks as a single bond. In general, depending of the rotation, some bonds will look as double and some will lokk as single bonds, quite disturbing. Rendering directly on 2D screen means the bonds always look as double lines, as expected.

Another mildly inconvenient effect is, when your molecule is closer and closer, the two lines naturally will move apart from each other, as they are getting closer. Rendering the bond directly on
pixel 2D space, they have always the same size, which is much better for analysis.

In this case, too much realism is bad. Anyway, getting the background color with

glGetFloatv (GL_COLOR_CLEAR_VALUE, background);

helps to decrease argument passing and simplifies my code. And the behaviour is just fine. I was just wondering if OpenGL does not have a mechanism to define line patterns, normal to the line direction...

For example, how can I render a line from point xyz1 to point xyz2 in 3D space, with this pattern?

/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_

jcgp
03-09-2006, 02:49 PM
It really depends of what you want to achieve.

In my case, I need this to represent double/triple chemical bonds. iF I use two real lines, side by side, when I rotate the molecule 90 degrees both lines will be in the same plane, normal to the screen, and the bond looks as a single bond. In general, depending of the rotation, some bonds will look as double and some will lokk as single bonds, quite disturbing. Rendering directly on 2D screen means the bonds always look as double lines, as expected.

Another mildly inconvenient effect is, when your molecule is closer and closer, the two lines naturally will move apart from each other, as they are getting closer. Rendering the bond directly on
pixel 2D space, they have always the same size, which is much better for analysis.

In this case, too much realism is bad. Anyway, getting the background color with

glGetFloatv (GL_COLOR_CLEAR_VALUE, background);

helps to decrease argument passing and simplifies my code. And the behaviour is just fine. I was just wondering if OpenGL does not have a mechanism to define line patterns, normal to the line direction...

For example, how can I render a line from point xyz1 to point xyz2 in 3D space, with this pattern?

/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_/\_

03-09-2006, 03:33 PM
Your problem is clearer now, but the end effect is still a tad vague to me.

Off the top of my head, I'd suggest using textured quads, since you can achieve any pattern whatever, and you can assure proper screen-space projection by using an appropriately scaled billboard. You can do this with lines, too, by always supplying lines in the plane parallel to the view, but a consistent pattern (presumably in the direction of the line) remains a problem.

By the way, my chemistry is a bit rusty :)

songho
03-09-2006, 04:34 PM
jcgp,
Actually, I like your 2-pass drawing trick and I think it is quite effective and very simple.

You may write the 1-pixel width line on the stencil buffer first, then write the 3-pixel one on the color buffer with stencil test. You will get the same effect, but your method is much simpler to me.

At least, you don't have to get the background colour, though. :)
==song==

jcgp
03-11-2006, 02:43 PM
simplex, songho,

Many thanks for your help,
Is working nice, I think,

Carlos