Hello,
I render a textured heightmap in OpenGL but the performance is too bad, because I calculate at each redraw the whole render order of 240x240 pixels (and that many times).
The performance of one chunk is good, but if i duplicate the loop to test the performance for later, the performance is too bad.
Here is a plan how i calculate the render order of one chunk:
[ATTACH=CONFIG]138[/ATTACH]
X in the middle = Player position, the red box the heightmap border, the arrows and numbers are the order, and then there are the 2 black axis that build the cross.
and the code to draw it:
hmt.getTexture().bind(gl);
gl.glCullFace(GL.GL_FRONT);
for(int i = 0; i < (int)(cam1.getXPos() * 10); i++){
gl.glBegin(GL.GL_TRIANGLE_STRIP);
for(int j = 0; j <= (int)((cam1.getZPos()) * 10); j++){
gl.glTexCoord2f((float)i / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)i / 10, (float)hm.getData(i, j) / 100 - 10, (float)j / 10);
gl.glTexCoord2f((float)(i+1) / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i+1) / 10, (float)hm.getData(i+1, j) / 100 - 10, (float)j / 10);
}
gl.glEnd();
}
for(int i = 238; i > (int)(cam1.getXPos() * 10); i--){
gl.glBegin(GL.GL_TRIANGLE_STRIP);
for(int j = 239; j > (int)((cam1.getZPos()) * 10); j--){
gl.glTexCoord2f((float)(i+1) / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i+1) / 10, (float)hm.getData(i+1, j) / 100 - 10, (float)j / 10);
gl.glTexCoord2f((float)i / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i) / 10, (float)hm.getData(i, j) / 100 - 10, (float)j / 10);
}
gl.glEnd();
}
gl.glCullFace(GL.GL_BACK);
for(int i = 0; i <= (int)(cam1.getXPos() * 10); i++){
gl.glBegin(GL.GL_TRIANGLE_STRIP);
for(int j = 239; j >= (int)((cam1.getZPos()) * 10); j--){
gl.glTexCoord2f((float)i / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)i / 10, (float)hm.getData(i, j) / 100 - 10, (float)j / 10);
gl.glTexCoord2f((float)(i+1) / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i+1) / 10, (float)hm.getData(i+1, j) / 100 - 10, (float)j / 10);
}
gl.glEnd();
}
for(int i = 238; i >= (int)(cam1.getXPos() * 10); i--){
gl.glBegin(GL.GL_TRIANGLE_STRIP);
for(int j = 0; j <= (int)((cam1.getZPos()) * 10)+1; j++){
gl.glTexCoord2f((float)(i+1) / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i+1) / 10, (float)hm.getData(i+1, j) / 100 - 10, (float)j / 10);
gl.glTexCoord2f((float)i / 239.0f, (float)j / 240.0f);
gl.glVertex3f((float)(i) / 10, (float)hm.getData(i, j) / 100 - 10, (float)j / 10);
}
gl.glEnd();
}
Is there a better way to do this?