PDA

View Full Version : textures not always drawing over lines



jbich
11-25-2010, 05:56 PM
Hi all.

I'm sure this has been covered before but I've googled like mad and haven't found an answer.

http://www.intuitivecreations.com/mapEditor.jpg

The textures are drawn after the lines are drawn. There shouldn't be any floating point issues as I'm using int values for everything.

Why are the lines coming through the textures?

Thanks for any insight you may be able to provide!

j

ZbuffeR
11-25-2010, 11:30 PM
Depth test ?

jbich
11-26-2010, 12:26 PM
Nope. I've tried the depth test both ways and it doesn't seem to effect it.

I was thinking it may have something to do with the borders of the textures and I've messed with related settings quite a lot but nothing seems to fix it.

ZbuffeR
11-26-2010, 02:51 PM
Not texture borders, more vertex coordinates.
Disable depth test if you want to rely on drawing order.
Try to trim the relevant code until it fits in a few lines, and post it here.
Often you will even see the problem yourself right before posting it.
:)

You card and OS ?

mhagain
11-26-2010, 03:52 PM
Lines aren't invariant with filled polygons.

http://www.opengl.org/resources/faq/technical/polygonoffset.htm


For coplanar lines and polygons, vastly different depth values for common pixels can result. This is because depth values from polygon rasterization derive from the polygon's plane equation, while depth values from line rasterization derive from linear interpolation.

jbich
11-27-2010, 12:02 PM
Hey Guys.

Wow, that was hugely insightful for me. I never realized (stupidly) that there would be drawing issues with drawing polygons on the same plane, I just figured (again stupidly) that it would simply draw them in the order you tell it to.

I've read a ton about polygonoffset and family now - thanks to you guys - and messed with the code a bit and I've gotten almost all of the issues solved.

I'm now down to this:
http://intuitivecreations.com/mapEditor1.jpg

So, I've enabled GL_POLYGON_OFFSET_FILL and GL_POLYGON_OFFSET_LINE, and I've marked the textures that are supposed to draw over the lines with an offset of -1,-1. This, as you can see almost completely eliminates the problem. However, the very outer border lines still get drawn (and are random which ones draw as you move the camera around the scene).

Is this still a polygonoffset issue or am I facing something new here?

Alfonse Reinheart
11-27-2010, 02:28 PM
Why are you using polygon offset? If you want OpenGL to draw stuff in the order you send it, just turn off the depth test.

jbich
11-28-2010, 09:39 AM
When I turn off depth testing, I get the picture in the first post.

Alfonse Reinheart
11-28-2010, 11:05 AM
Are you sure you turned it off? Try explicitly drawing one thing in front of another, but drawing the object that is behind last.

Without depth test, there is no way for OpenGL to draw over something unless you actually draw over it yourself. So you've either not turned off depth test, or your rendering order is screwy.

jbich
11-28-2010, 11:42 AM
Your post got me thinking.

I explicitly disabled depth testing and modified the drawing routine from


void Map::draw() {
if (mapLength <= 0 || mapWidth <= 0) { return; }
for (int i = 0; i < mapWidth; i++) {
for (int a = 0; a < mapLength; a++) {
tiles[i][a].drawBelowTiles();
tiles[i][a].drawGrid();
tiles[i][a].drawAboveTiles();
}
}
}


to



void Map::draw() {
if (mapLength <= 0 || mapWidth <= 0) { return; }
for (int i = 0; i < mapWidth; i++) {
for (int a = 0; a < mapLength; a++) {
tiles[i][a].drawBelowTiles();
}
}
for (int i = 0; i < mapWidth; i++) {
for (int a = 0; a < mapLength; a++) {
tiles[i][a].drawGrid();
}
}
for (int i = 0; i < mapWidth; i++) {
for (int a = 0; a < mapLength; a++) {
tiles[i][a].drawAboveTiles();
}
}
}


This results in the second picture I posted where I still get the lines around the outer border but it correctly draws over all other lines.

Cool, so we have two solutions that give me almost all of what I want, and disabling the depth test is much easier than using polygonoffset. :)

I'm still a bit confused as to why I get lines on the very outside of the map though...