Archived

This topic is now archived and is closed to further replies.

Getting single pixel lines with GL_LINE_STRIP

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

For some reason, i can't convince openGL to give me single pixel wide lines, and insists on producing slightly dodgy and flickery lines
They look sort of like this:
*
*
**
**
 *
 *
 **
 **
  *
  *
 
Also, even dead vertical/horizontal lines 'shimmer' when i scroll my camera, they seem to flick between a single and a double line of pixels, with the intensity changing as well I've disabled antialiasing with:
		gl.lineWidth(1);
		gl.disable(GL.LINE_SMOOTH);
		gl.hint(GL.LINE_SMOOTH, GL.FASTEST);
 
but i think its something to do with my perspective projection perhaps. Maybe my aspect ratio is causing problems?
		gl.matrixMode(GL.PROJECTION);
		gl.loadIdentity();
		
		double aspect = Display.getWidth()/Display.getHeight();
		//				fov	aspect	nearZ	farZ
		glu.perspective(90,	aspect,		0,		100);
		
		gl.matrixMode(GL.MODELVIEW);
		gl.loadIdentity();
		
		gl.viewport(0, 0, Display.getWidth(), Display.getHeight());
  
Anyone any ideas for a n00b to try? _@/ [edited by - OrangyTang on September 8, 2002 2:19:18 PM]

Share this post


Link to post
Share on other sites
It's called aliasing (i.e. you haven't "disabled" antialiasing with your code; you've tried to enable it). Look up how to draw "antialiased lines" with OpenGL. For starters:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
// draw lines.
glDisable(GL_BLEND);


[edited by - zealouselixir on September 8, 2002 10:17:58 PM]

Share this post


Link to post
Share on other sites
Ok, if i''ve accidentally enabled some sort of antialiasing, how do i disable it? I don''t want smoothed lines, just single pixel, so i get nice crisp, *non shimering* lines on compass points. I know this has to be possible, it seems to be the most common form of wireframe mode avalible in other apps..

Share this post


Link to post
Share on other sites
No, it's quite frankly not possible.
EDIT : Okay, it's possible, but I don't know how unless you just do something like glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

Think about it like this: your monitor has a certain number of pixels (from whence your 'resolution' is derived). When you draw a line from point A to point B, a piece of software called a rasterizer is invoked, and its job is to determine which pixels on your monitor accurately represent your line.

If you had infinite resolution, the artifacts you're experiencing wouldn't be an issue. However, there's something called the Diamond Pixel Principle (or something like that); basically, each pixel on your screen is surrounded by a virtual diamond, and during rasterization, if the calculated value of the line at a given point is within the diamond, the pixel gets turned on.

That's why with lines that aren't perfectly horizontal or vertical, you sometimes get 'overlapping' pixels. It would actually look *worse* if you rasterized lines so that they were *always* exactly 1 pixel thick.
EDIT : That's mostly false, I suppose.

For this reason, antialiasing was introduced. Basically, antialiasing uses a kind of blurring effect, similar to font kerning, to make the lines look as though they're very thin, but that they also don't have ugly visual glitches.

Why is it so necessary that you have lines that are precisely one pixel thick and lack antialiasing?

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


[edited by - zealouselixir on September 9, 2002 7:09:03 PM]

Share this post


Link to post
Share on other sites
This is silly, i''ve *seen* lines as i''m trying to get when learning Java3D, and thats just built on OpenGL as a core. And its always been like that with games in wireframe mode etc.

More to the point, even lines that should be dead vertical/horizontal still flicker and look crap.

Yes I know what aliasing is and how smoothing/averaging stops it, but thats not what i''m getting at - if i want nice lines i''ll turn that on, for now i''m just trying to get basic lines drawn fast - no blending, just a line!

Share this post


Link to post
Share on other sites
Can you post a screenshot, or better yet, the line drawing code? It seems rather dodgy that your vertical lines are still flickering...

Sorry for assuming your ignorance, it just seems like the gl isn''t the problem here.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites
Er, ok, i kinda messed up and kinda not...

I just ran npr Quake just to check that i''m not going slightly funny in the head, and it seemed all good as i was expecting/aiming for. Then I tinkered with my code, and lo! it worked.. except that I didnt actually change anything.

I think that there was some odd driver anti-aliasing going on (despite me manually disabling it) that npr quake seems to have forced to off. So my code now runs as expected


Trying to learn openGL with the lightweight java game library is not making things especially easy on me :o

Share this post


Link to post
Share on other sites