PDA

View Full Version : GL_LINES looks weird



Troxtril
09-28-2008, 11:22 PM
hey,

I'm trying to draw grid lines in 2d ortho. proj. where the ortho delta depends on user input value delta.

the line width is 1.0f and all lines are in same color and 1.0f alpha but the lines look weird like some are light and some are dark, some has thickness of 2 pixels and some 1 pixel as shown in screenshot below.

I tried all combinations of enabling and disabling Line and Point smoothing and alpha blending.

I realized it can be because my orthographic delta isn't scaled with screen delta and my points aren't actually hitting the actual pixel values in terms of orthographic coordinates.

is there a method to solve this problem?

here comes the screenshot:

http://www.fomgrup.com/ng/sshot2.jpg

remdul
09-29-2008, 11:46 AM
Try thicker lines if you use line smoothing, something like 1.33 is good. They will all be a bit thicker, but look more consistent.

You cay also try setting glHint to GL_NICEST, though I've never seen an implementation that differentiated the slightest between GL_FASTEST and NICEST.

I you really want 1px wide lines, disable line smoothing and make sure you pass the right coordinates. Also check out the FAQ about line rasterization: http://www.opengl.org/resources/faq/technical/rasterization.htm

Troxtril
09-30-2008, 01:56 AM
I you really want 1px wide lines, disable line smoothing and make sure you pass the right coordinates.

aw. it's ridiculous to adapt your mathematical equations to a graphics api instead of adapting the api to your maths.

Xmas
09-30-2008, 07:37 AM
aw. it's ridiculous to adapt your mathematical equations to a graphics api instead of adapting the api to your maths.
It isn't adapting to a graphics API but adapting to the reality of discrete raster graphics.

Troxtril
09-30-2008, 09:48 AM
It isn't adapting to a graphics API but adapting to the reality of discrete raster graphics.

oh well.. I choose constant line attributes and it decides to create them in various widths and colors with no api-side correction just because my value range does not cover "discrete raster graphics'" reality range?

what if it's a scientific project which should be error-free? oh I can see the newsflash on TV after space shuttle accident "Shocking Confession from Engineers: We considered PI as 3. discrete raster graphics..."

btw this is not about you xmas. I'm just tired and angry. many thanks u both for trying to help.

CatDog
09-30-2008, 10:05 AM
You're kidding, aren't you?

You don't have to adjust your value range, you simply have to align the scale of the grid to evenly fit display resolution.

CatDog

Xmas
10-01-2008, 06:19 AM
oh well.. I choose constant line attributes and it decides to create them in various widths and colors with no api-side correction just because my value range does not cover "discrete raster graphics'" reality range?
It is called antialiasing. A one pixel wide line at fractional coordinates should not look the same as a one pixel wide line on integer coordinates. You'd be ignoring position information.

Your result looks like you have multisample antialiasing enabled. If you don't like what you get, you can either disable it or align your lines to the pixel grid.


what if it's a scientific project which should be error-free? oh I can see the newsflash on TV after space shuttle accident "Shocking Confession from Engineers: We considered PI as 3. discrete raster graphics..."
Mapping a continuous space to a discrete space (pixel raster) won't be error-free. The result you expect isn't more "correct" than the result you get at the moment.