Java 在OpenGL中生成二维地形的问题

Java 在OpenGL中生成二维地形的问题,java,opengl,libgdx,terrain,vertex-array,Java,Opengl,Libgdx,Terrain,Vertex Array,不久前,我询问了如何使用opengl顶点制作2D地形。我得到了一个很好的答案,但当我尝试它的时候,它没有画出任何东西,我也不知道是什么问题,或者如何修复它 我现在有: public class Terrain extends Actor { Mesh mesh; private final int LENGTH = 1500; //length of the whole terrain public Terrain(int res) { Random r = new Random(

不久前,我询问了如何使用opengl顶点制作2D地形。我得到了一个很好的答案,但当我尝试它的时候,它没有画出任何东西,我也不知道是什么问题,或者如何修复它

我现在有:

public class Terrain extends Actor {

Mesh mesh;
private final int LENGTH = 1500; //length of the whole terrain

public Terrain(int res) {

    Random r = new Random();

    //res (resolution) is the number of height-points 
    //minimum is 2, which will result in a box (under each height-point there is another vertex)
    if (res < 2)
        res = 2;

    mesh = new Mesh(VertexDataType.VertexArray, true, 2 * res, 50, new VertexAttribute(Usage.Position, 2, "a_position")); 

    float x = 0f;     //current position to put vertices
    float med = 100f; //starting y
    float y = med;

    float slopeWidth = (float) (LENGTH / ((float) (res - 1))); //horizontal distance between 2 heightpoints


    // VERTICES
    float[] tempVer = new float[2*2*res]; //hold vertices before setting them to the mesh
    int offset = 0; //offset to put it in tempVer

    for (int i = 0; i<res; i++) {

        tempVer[offset+0] = x;      tempVer[offset+1] = 0f; // below height
        tempVer[offset+2] = x;      tempVer[offset+3] = y;  // height

        //next position: 
        x += slopeWidth;
        y += (r.nextFloat() - 0.5f) * 50;
        offset +=4;
    }
    mesh.setVertices(tempVer);


    // INDICES
    short[] tempIn = new short[(res-1)*6];
    offset = 0;
    for (int i = 0; i<res; i+=2) {

        tempIn[offset + 0] = (short) (i);       // below height
        tempIn[offset + 1] = (short) (i + 2);   // below next height
        tempIn[offset + 2] = (short) (i + 1);   // height

        tempIn[offset + 3] = (short) (i + 1);   // height
        tempIn[offset + 4] = (short) (i + 2);   // below next height
        tempIn[offset + 5] = (short) (i + 3);   // next height

        offset+=6;
    }
}

@Override
public void draw(SpriteBatch batch, float delta) {
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    mesh.render(GL10.GL_TRIANGLES);
}
公共类地形扩展演员{
网目;
私有最终整数长度=1500;//整个地形的长度
公共地形(国际分辨率){
随机r=新随机();
//res(分辨率)是高度点的数量
//最小值为2,这将生成一个长方体(每个高度点下有另一个顶点)
如果(res<2)
res=2;
网格=新网格(VertexDataType.VertexArray,true,2*res,50,新的VertexAttribute(Usage.Position,2,“a_位置”);
float x=0f;//放置顶点的当前位置
浮点中值=100f;//开始y
浮动y=med;
float slopeWidth=(float)(长度/(float)(res-1));//两个高度点之间的水平距离
//顶点
float[]tempVer=new float[2*2*res];//在将顶点设置到网格之前保持顶点
int offset=0;//将其放入tempVer的偏移量

对于(int i=0;i在一整天过去之后,我尝试了所有方法来解决它,但似乎我忘记了实际设置网格的索引


少了一行,几个小时的痛苦……我是个白痴:)

你确定没有渲染任何东西吗?可能是你相机的位置。
mesh.setIndices(tempIn);