Line capping & wide lines

I’m fairly new to openGL and have written a simple 2d program to draw some connected wide lines. One part of the program draws to 2 end to end lines of width 10. I find that the lines are rendered differently on 2 different computers…on one there is a small gap between the lines since the line ends are not capped and the lines are not parallel. On another computer, the gap does not appear. Both computers are running Windows XP with the same openGL version, so I assume the graphics card is affecting the way the lines are capped (or not, as the case may be). Further, on one computer, I cannot seem to render lines with a line width > 10.

My question is simply how can I render connected lines without gaps regardless of the computer’s graphics card and also how can I render lines wider than 10 such that they are always displayed with the width that I specify?

Also, are there other issues I should be aware of that may affect the rendering of a 2D scene due to different graphics card implementations?

It seems that it doesn’t support the values that are greater than 10.Some books have written that there’s no limitation about the line with when you don’t use from the line smooth. But as i have executed it in my system, it doesn’t suppot the values > 10.
When you enable the line smooth, you can query the range of the supported values with the glGet function.Here’s an example that determines the supported range:

glEnable( GL_LINE_SMOOTH );
GLfloat sizes[2];
glGetFloatv( GL_LINE_WIDTH_RANGE, sizes );
cout<<sizes[0]<<’
‘<<sizes[1]<<’
';
-Ehsan-

Originally posted by npf100:

My question is simply how can I render connected lines without gaps regardless of the computer’s graphics card and also how can I render lines wider than 10 such that they are always displayed with the width that I specify?

The common approach is to draw quads instead of lines.

This approach has of course some pros and cons:

Pro:
Speed, line rendering isnt really optimised on consumer level hardware.

Con:
The computation required to “emulate” lines with quads has to be done manually.

Whocares, thanks for that suggestion.

I actually tried this but I found that quads don’t render as I would hope with my graphics card. Specifically, when I draw a quad, a jagged line appears between 2 opposite verticies of the quad.
eg.
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
glBegin(GL_QUADS);

glVertex2d(10,10);
glVertex2d(30,10);

glVertex2d(30,20);
glVertex2d(10,15);
glEnd();

… this renders with a jagged line of unfilled pixels between (30,20) and (10,10). This appears to be because the quad has been rendered as 2 triangles, but the face of one of the triangles has not been aliased. I can confirm this by drawing the equivalent 2 triangles, with the same result. The strange thing is that if I draw either of the triangles individually without the other present, then all sides of the triangle are correctly aliased. But when I draw them both together, the common face of the 2 triangles does not appear to be aliased on the second triangle.

Any suggestions regarding how to resolve this problem?

Yes. I think that’s software rendering. Check your OpenGL initialisation code (PIXELFORMATDESCRIPTOR on Win32).
Also call glGetString(GL_RENDERER). If it returns something like PFD_GENERIC_blahblah that’s software render.

Use glGet* with GL_ALIASED_LINE_WIDTH_RANGE.

There are definitely line width limits. Capping is also usually crap or non existent. Lines are typically replicated horizontally or vertically depending on slope so no capping is required but where the angle transitions 45 degrees there is a nasty gap in the capping, the width on diagonals is also questionable given this method, wasn’t there another thread about this recently?

Even with capping it’s only possible with a gl_LINE_STRIP and LINE_LOOP, individual lines will leave a gap on a high quality implementation but look OK on a poor implementation (depending on the angles), the opposite of what you may expect.

You may get better results of you use glHint to make antialiased line quality highest, but you’ll have to enable line_smooth, blending, and query GL_SMOOTH_LINE_WIDTH_RANGE instead of the aliased range. Again your results may vary.

Do yourself a favor and use quads.

Thanks for the replies.

I am trying to use Quads, but the problem is that I can’t even render a simple quad without a line appearing down the middle as described above.

Calling glGetString(GL_RENDERER) returns “RADEON 7000 SW TCL x86/SSE2”.

Originally posted by npf100:
I am trying to use Quads, but the problem is that I can’t even render a simple quad without a line appearing down the middle as described above.

That’s most commonly happening when you have GL_POLYGON_SMOOTH enabled and used depth testing or the wrong blending mode.
See if it goes away when not enabling GL_POLYGON_SMOOTH.