View Full Version : Diagonal line across transluscent rectangle
02-09-2006, 11:59 PM
This is probably a newbie question, but... I am drawing a white semi-transparent rectangle over a background, and I am seeing a visible diagonal line from (left, bottom) corner to (right, top) corner of my rectangle. Here are the things I am doing:
- Using a pixel format supports multi-sampling (WGL_SAMPLE_BUFFER_ARB = GL_TRUE) on windows XP, NVIDIA GeForce FX5200
- glBlend(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA)
- glPolygonMode(GL_FRONT, GL_FILL)
And to draw the rectangle:
w_div_2 = width / 2.0f;
h_div_2 = height / 2.0f;
glColor4ub(255, 255, 255, 150);
glVertex3f(-w_div_2, -h_div_2, 0.0f);
glVertex3f( w_div_2, -h_div_2, 0.0f);
glVertex3f( w_div_2, h_div_2, 0.0f);
glVertex3f(-w_div_2, h_div_2, 0.0f);
Would anyone care to guess what's making a white diagonal line appear across my semi-transparent rectangle?
Thanks in advance,
02-10-2006, 12:33 AM
I actually could get rid of the diagonal line by turnning on multi-sampling. (I had it off, and was only enabling it for parts of the scene that needs anti-aliasing).
So, it seems that if I have multi-sampling buffer but disable multi-sampling, the lines along tessalation seems to appear.
This is interesting and I'd be interested in hearing anybody's further insight on this.
Thanks, good night.
02-10-2006, 12:35 AM
The multisample fact irritates me a little, but this problem normally appears with depth buffered antialiased polygons when using glEnable(GL_POLYGON_SMOOTH).
Do you actually have multisampling enabled and a buffer with multiple samples? If yes, that would change the rasterization rules for antialiased primiteves and smoothing should not have an effect.
Does it change with depth buffering disabled?
(edit: Nice double post...)
If this is rendering a full screen quad, it could be that you have position imprecisions and there is actually another sliver triangle generated. I had such a case about 8 years ago. ;-)
Use a perfect gluOrtho2D setup using (0, 0, width, height) and render the quad from (0, 0), to (width, height) to cover pixel perfectly.
Nitpick: You should move the color call before the begin.
I am seeing a similar problem. Code is basically the same, using glOrtho to look at z=0 plane. Depth buffer and multisampling disabled:
and to draw:
// tried this
glRectf(x1, y1, x2, y2);
// and this
// and this
glEdgeFlag(true); glVertex2f(x1, y1);
glEdgeFlag(true); glVertex2f(x2, y1);
glEdgeFlag(false); glVertex2f(x2, y2);
glEdgeFlag(true); glVertex2f(x2, y2);
glEdgeFlag(true); glVertex2f(x1, y2);
glEdgeFlag(false); glVertex2f(x1, y1);
I get the diagonal line no matter which way I draw it. Seems like it is incorrectly treating the diagonal as boundary edges and so blending, but I want them to be non-edge boundaries.
Is this a standard problem and if so how to fix it? I have worked around it by drawing the rectangle twice, specifying the corners in opposite order, which masks the worst of the problem.
02-10-2006, 03:46 AM
:confused: Edge flags do nothing in fill mode.
Yes, polygon smoothing has this problem. It basically sucks due to a number of restrictions.
Normally you use it with depth buffering disabled, front to back sorted polygons, destination alpha channel in the pixel format(!), and blending set to saturate on the destination like describe in the OpenGL Programming Guide.
I've never tried this on multisample formats. Antialiasing should better be done with the multisampling itself.
02-10-2006, 05:24 AM
By the way, depth buffer doesn't seem to affect the diagonal line when using multisample buffer; that is, the line is still visible with depth test off.
But with multisampling enabled, it goes away, which is kind of a pity since I wanted to render most of my scene without multisampling, and only enable multisampling as needed. (e.g. when rendering outlined font).
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.