我對我的遊戲的fps有點失望。我仍然處於遊戲開發的開始階段。當我首先開始我的比賽時,我的速度達到了350 fps。在我爲程序添加了一個高度圖和更多代碼之後,fps下降是否合乎邏輯。現在我得到了39 fps。 我還處於起步階段,fps已經很低。我想知道當我完成這個項目時會發生什麼,我認爲fps會很低,以至於令人不快。 我知道我非常需要這個程序,高度圖是個大問題。 地圖有200 * 200頂點的面積,每個頂點都有一個高度。 200 * 200 = 40000個頂點,每個幀。 我在想簡化地圖。我的想法是創建一個簡化整個高度圖的方法。每4個頂點屬於一個四元組。當每個頂點有兩個或更多相鄰高度相同的四邊形時,它們可以合併爲一個四邊形。 重點是應該有更少的頂點。 (我認爲)Lwjgl如何簡化高度圖以獲得更高的fps?
我將顯示我的高度圖的一些示例代碼。
package rgc.area;
import java.awt.Dimension;
import java.util.ArrayList;
import java.util.List;
public class HeightMap {
public int width; // Vertices (width)
public int height; // Vertices (height)
public List<Float> map = new ArrayList<Float>();
/**
*
* @param width The width of the map (x-axis)
* @param height The height of the map (z-axiz, NOT y-axis);
*/
public HeightMap(int width, int height) {
this.width = width;
this.height = height;
for(int i = 0; i < width * height; i++) {
map.add(1.0f);
}
}
public Dimension getSize() {
return new Dimension(this.width, this.height);
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
/**
* Set the height of a vertex of the map
*/
public void setHeight(int x, int y, float h) {
int index = x;
if(y > 0) {
index += (y - 1) * width;
}
map.set(index - 1, h);
/* DEBUG
for(int i = 0; i < map.size(); i++) {
System.out.println(i + " height: " + map.get(i));
}
*/
}
public float getHeight(int x, int y) {
int index = x;
if(y > 0) {
index += (y - 1) * width;
}
return map.get(index);
}
public float getHeight(float x, float y) {
return this.getHeight((int)x, (int)y);
}
/**
* This method simplifies the heightmap.
* It will merge seperate quads with the same vertex heights.
* This is to save memory and render faster.
*
* This method should only be called when the heightmap is changed.
* So this method should NOT be called every frame.
*/
public void simplify() {
// Don't really know how to do this.
for(int i = 0; i < width * height; i++) {
for(int w = 1; w < width - 1; w++) {
if(map.get(i) == map.get(i + w)) {
}
}
}
}
}
有沒有人有這方面的經驗? 是否有任何想法或改進,並且是我正確地做它的方式? 在此先感謝。
也許你可以得到一些更多的幫助[這裏](http://gamedev.stackexchange.com/) – Leviathan
那麼。這是一個高度圖。重要的是:你怎麼樣渲染它?現代圖形卡上的40k頂點應該幾乎不可顯示。但是,如果像glVertex3f(x,y,map.getHeight(x,y))那樣涉及某些東西,那麼我可以想象這太慢了。 (順便說一句:通過用一個簡單的'float []'數組替代'List'就可以實現一個明顯的改進,但爲了獲得真正的高性能,你應該考慮頂點緩衝對象(VBO)和其他「現代」OpenGL東西) –
Marco13
使用VBO。這將有所幫助。 –