textures not always drawing over lines

Hi all.

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

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

Depth test ?

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.

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.
:slight_smile:

You card and OS ?

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.

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:

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?

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.

When I turn off depth testing, I get the picture in the first post.

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.

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. :slight_smile:

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