I'm trying to improve my frame rates.
My map has an area of 200 * 200 vertices, where each vertex has a height. 200 * 200 = 40000 vertices per frame.
I'd like to create a method to simplify the whole heightmap (i.e. decrease vertex count). Every 4 vertices form a quad, so when there are 2 or more adjacent quads with the same height on each vertex, they could be merged.
How do I detect and merge vertices like that?
My height map is a list of float
s representing the height of each vertex. The list is indexed by an x
and y
coordinate.
package rgc.area;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
public class Terrain {
private HeightMap map;
public Terrain(HeightMap map) {
this.map = map;
}
public void render() {
float spaceBetwVert = 1f; // Space between each vertex
GL11.glColor3f(0.1f, 1.0f, 0.2f);
GL11.glBegin(GL11.GL_QUADS);
for(int i = 0; i < map.getHeight() - 1; i++) {
for(int ii = 0; ii < map.getWidth(); ii++) {
GL11.glColor3f(0.1f, 1.0f - ii * 0.1f, 0.2f);
float vz = i * spaceBetwVert;
float vx = ii * spaceBetwVert;
float nextVz = (i + 1) * spaceBetwVert;
float nextVx = (ii + 1) * spaceBetwVert;
GL11.glVertex3f(vx, map.getHeight(vx, vz), vz - 80);
GL11.glVertex3f(nextVx, map.getHeight(nextVx, vz), vz - 80);
GL11.glVertex3f(nextVx, map.getHeight(nextVx, nextVz), nextVz - 80);
GL11.glVertex3f(vx, map.getHeight(vx, nextVz), nextVz - 80);
}
}
GL11.glEnd();
}
}