Pergunta

I'm currently rendering triangle strips within a display list and it shows weird little holes.

Beside that some triangles seem to disappear completely when rotating the environment.
Here is the Code:

public class Landscape {

    int displayList;

    public Landscape() throws IOException {
        try {
            Display.setDisplayMode(new DisplayMode(640, 480));
            Display.create();
        } catch (LWJGLException e) {
            e.printStackTrace();
        }

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        GLU.gluPerspective(60f, 640f/480f, 0.0001f, 1000f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LEQUAL);
        glPolygonMode(GL_FRONT_AND_BACK, GL_FLAT);
        glEnable(GL_CULL_FACE);

        BufferedImage heightMap = ImageIO.read(new File("heightmap.png"));
        BufferedImage heightMapColor = ImageIO.read(new File("hoehenprofil.png"));
        displayList = glGenLists(1);
        glNewList(displayList, GL_COMPILE);
        for (int z = 0; z < heightMap.getHeight(); z++) {
            glBegin(GL_TRIANGLE_STRIP);
            for (int x = 0; x < heightMap.getWidth(); x++) {
                int y = 0xFF - heightMap.getRGB(x, z) & 0xFF;
                int color = heightMapColor.getRGB(y-1, 0);
                glColor3ub((byte)((color >> 16) & 0xFF), (byte)((color >> 8) & 0xFF), (byte)(color & 0xFF));
                glVertex3i(x, y*5, z);
                if (z < heightMap.getHeight() - 1) {
                    y = 0xFF - heightMap.getRGB(x, z+1) & 0xFF;
                    color = heightMapColor.getRGB(y-1, 0);
                    glColor3ub((byte)((color >> 16) & 0xFF), (byte)((color >> 8) & 0xFF), (byte)(color & 0xFF));
                    glVertex3i(x, y*5, z+1);
                }
            }
            glEnd();
        }
        glEndList();

        float camX = 500, camY = 500, camZ = -500;
        float rotX = 45, rotY = 0, rotZ = 0;
        long lastTick = System.currentTimeMillis();
        int fps = 0;
        while (!Display.isCloseRequested()) {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glLoadIdentity();
            if (Keyboard.isKeyDown(Keyboard.KEY_W)) camZ++;
            if (Keyboard.isKeyDown(Keyboard.KEY_S)) camZ--;
            if (Keyboard.isKeyDown(Keyboard.KEY_A)) camX--;
            if (Keyboard.isKeyDown(Keyboard.KEY_D)) camX++;
            if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) camY++;
            if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) camY--;
            if (Keyboard.isKeyDown(Keyboard.KEY_Q)) rotY -= 0.5f;
            if (Keyboard.isKeyDown(Keyboard.KEY_E)) rotY += 0.5f;
            glRotatef(rotX, 1, 0, 0);
            glRotatef(rotY, 0, 1, 0);
            glRotatef(rotZ, 0, 0, 1);
            glTranslatef(-camX, -camY, camZ);
            glCallList(displayList);
            Display.update();

            fps++;
            if (lastTick + 1000 <= System.currentTimeMillis()) {
                lastTick += 1000;
                System.out.println("FPS: " + fps);
                fps = 0;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        new Landscape();
    }
}

It seem to also appear with depth test disabled. And even with cull face enabled this doesn't appear to work.

EDIT:
Other than that I get some black flickering just when translating a certain amount around the x or y axis. Here is a screenshot of that.

It causes a huge amount of lag and I can't find any reason for that.

EDIT2:
I scaled the x and z axis and removed the y axis scale for a screenshot, just as requested. It only seem to cause the bug when stretching far around the y axis.

Foi útil?

Solução

Your difference between near and far plane (last two arguments to gluPerspective) is extremely large. The larger the relative size (far divided by near) between these two, the less depth buffer precision you get. In your case, the far/near is 1,000,000, which is much more than you normally want. I normally like to keep them at a ratio of around 10, even though something like 100 would probably still be fine.

Tweak the values while making sure that none of the geometry you want to see gets clipped away. Try something like 1.0 and 10.0. If that clips away geometry at the far end, increase the far value to something like 100.0, and maybe see if you can increase the near value as well.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top