PDA

View Full Version : Overlapping lines



devdept
01-12-2008, 01:11 AM
Hi All,

Here is my latest question:

I have a 3D shaded cube made by 6 faces drawn one by one with GL_QUADS and GL_LINE_LOOP for edges, I use:



gl.Enable(gl.POLYGON_OFFSET_FILL);
gl.PolygonOffset(1.0f, 1.0f);


to have Hidden Lines (edges) Removal.

In this way I see the shaded blue cube and the black edges drawn perfectly.

The problem arises when I select a cube face. I need to draw in yellow the shaded face and its boundary edge. When I do it and rotate the cube the edge change color unplesantly from black to yellow very frequently.

Is there a way to avoid this? To draw the yellow wire edges slightly closer to the user?


Thanks,

Alberto

ZbuffeR
01-12-2008, 02:27 AM
If there is flicker on the edges, it means you are drawing them more than once. A cube has only 12 edges, no need to drawn four edges aroung each face, it would mean 4 * 6 = 24 edges, with flickering.

devdept
01-12-2008, 03:41 AM
I know ZbuffeR, the cube is an example, in reality we work with 3D surface based models. Each surface has a fill and an outline and all around overlap with others.

Thanks,

Alberto

-NiCo-
01-12-2008, 05:32 AM
Maybe some other values for factor and units will do the trick?

N.

devdept
01-13-2008, 01:31 AM
As far as I know, glPolygonOffset() helps to separate wireframe from polygons not wireframe from wireframe.

Alberto

ZbuffeR
01-13-2008, 02:24 AM
But you can offset with a higher value just for selected wire.

devdept
01-13-2008, 09:54 AM
ZbuffeR,

Aren't only polygons affected by glPolygonOffset()? In my case I need to separate two lines.

Thanks,

Alberto

tamlin
01-13-2008, 12:39 PM
devdept, glPolygonOffset explained (http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/polygonoffset.html).

A line is in fact usually a polygon; a quad (that's deconstructed into two triangles).

devdept
01-13-2008, 02:44 PM
This is the first time I heard that a line is a polygon, do you all agree?

I will try to see what happen to apply again the glPolygonOffset() on lines.

ZbuffeR
01-13-2008, 02:49 PM
Apply the normal offset to the whole wire, then increase the offset, then render only the selected wire.

devdept
01-13-2008, 03:07 PM
Hi ZBuffeR,

We are following the RedBook Chapter 14 that says to apply glPolygonOffset on filled polygons not on wires. Can we do the opposite and use glPolygonOffset on wires with different factor for selected wires?

Thanks,

Alberto

-NiCo-
01-13-2008, 03:28 PM
You can always fake the polygonoffset by changing your projection matrix.

e.g.
1) draw the polygon with gluPerspective(....,near,far)
2) draw set of lines with gluPerspective(....,near+offset1,far+offset1)
3) draw set of lines with gluPerspective(....,near+offset2,far+offset2)
etc.

N.

devdept
01-17-2008, 03:13 AM
ZbuffeR,

I tryed to do what you suggested but using the glPolygonOffset on wires instead of polygons it pushes the polygons in front of wires even with negative factors.

NiCo,

Unfortuately in our Rendering engine we are not allowed to give different projection to different entities.


I am sure that a smarter solution exists.

Think about two overlapping lines: how would you make one always visible over the other?


Thanks,

Alberto

ZbuffeR
01-17-2008, 04:42 AM
ZbuffeR,
I tryed to do what you suggested but using the glPolygonOffset on wires instead of polygons it pushes the polygons in front of wires even with negative factors.

You are right, I mixed up polygons and wire. So polygon offset is out.

NiCo,
Unfortuately in our Rendering engine we are not allowed to give different projection to different entities.
I am sure that a smarter solution exists.

Too bad, sometimes that is very useful. It is not smart enough for you ?

Think about two overlapping lines: how would you make one always visible over the other?

1)Change projection as said nico
2)disable depth test, or maybe use "or equal" tests, and draw selected wire last. If your vertex coordinates and drawing commands are exactly the same (only color changes), it should work without glitches.
3)use a custom vertex shader to do 1)

-NiCo-
01-17-2008, 05:48 AM
If you don't want to change the projection matrix you can always change the modelview matrix to get the same effect. After all, the actual projection is only defined by projection*modelview...

N.

devdept
01-17-2008, 06:05 AM
Thanks guys.

I will try again.