얼마 전 OpenGL 버텍스로 2D 지형을 만드는 방법에 대해 this question에게 물었습니다. 나는 좋은 대답을 얻었지만 그것을 시도 할 때 아무 것도 그리지 않았고, 무엇이 잘못되었거나 그것을 고치는 법을 알 수 없었다.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);
}
이것은 또한 클래스 메쉬를 제공 Libgdx에 의해 렌더링되는,하지만 난 잘 작동 있다고 생각하기 때문에이 정말 관련이 없습니다 :
지금이 있습니다. 내 문제는 꼭지점과 지표 생성에 의해 결정됩니다. 나는 그것을 디버깅하는 방법을 모른다. 아무도 그것을보고 제발 렌더링 할 수없는 이유를 찾도록 도와 줄 수 있을까? 하루 종일이 경과하고, 나는 그것을 해결하기 위해 모든 노력을 한 후
당신이 아무것도 렌더링되고 있지 확실 해요? 카메라의 위치 일 수 있습니다. – PaulG