나는 이것이 매우 기본적인 질문이라는 것을 알고 있지만, Java에 익숙하지 않았고 Android 개발에 익숙하지 않았지만 강력한 C/C++ 배경과 OpenGL에서 작동하는 코드 내가 여기서 뭘하려고하는지.안드로이드의 OpenGL에서 FloatBuffer
기본 Cube.java 및 CubeRenderer.java 코드 샘플을 가져 와서 20 면체 데이터를 포함하도록 수정했습니다. 고정 대신 부동 소수점을 사용하고 싶지만 가능한지 또는 수행 방법을 모르겠습니다.
누군가 내가 잘못하고있는 것을 보여줄 수 있습니까? 오류없이 컴파일 및 시작되지만 흑백 만 보여줍니다. Cube()의 다른 드로잉 알고리즘은 같습니다. 나는 폰의 크기 (양수 1.0), 월 (1.0), pgr (양의 황금 비율), mgr (황금 비율 빼기)를 현재 값의 절반으로 줄이려고 시도했다. 여전히 렌더링 된 삼각형이 없음을 보여줍니다.
나는 정말 실망하고 어떤 도움을 주셔서 감사합니다.
미리 감사드립니다. :-)
class Icosahedron
{
public Icosahedron()
{
int one = 0x10000;
float zro = 0.0f;
float pon = 1.0f;
float mon = -1.0f;
float pgr = 1.618033989f;
float mgr = -1.618033989f;
float vertices[] = {
pgr, pon, zro,
pgr, mon, zro,
pon, zro, pgr,
pon, zro, mgr,
zro, pgr, pon,
zro, pgr, mon,
zro, mgr, pon,
zro, mgr, mon,
mon, zro, pgr,
mon, zro, mgr,
mgr, pon, zro,
mgr, mon, zro
};
int colors[] = {
0, 0, 0, one,
one, 0, 0, one,
one, one, 0, one,
0, one, 0, one,
0, 0, one, one,
one, 0, one, one,
one, one, one, one,
0, one, one, one,
0, 0, one, one,
one, 0, one, one,
one, one, one, one,
0, one, one, one,
0, 0, one, one
};
byte indices[] = {
0, 5, 4,
0, 4, 2,
0, 2, 1,
0, 1, 3,
0, 3, 5,
1, 6, 7,
1, 7, 3,
1, 2, 6,
2, 8, 6,
2, 4, 8,
3, 7, 9,
3, 9, 5,
4, 10, 8,
4, 5, 10,
5, 9, 10,
6, 11, 7,
6, 8, 11,
7, 11, 9,
8, 10, 11,
9, 11, 10
};
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asFloatBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);
mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
}
public void draw(GL10 gl)
{
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glColorPointer(4, GL10.GL_FIXED, 0, mColorBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, 20, GL10.GL_UNSIGNED_BYTE, mIndexBuffer);
}
private FloatBuffer mVertexBuffer;
private IntBuffer mColorBuffer;
private ByteBuffer mIndexBuffer;
}
맞아요. 두 번째 매개 변수는 '인덱스'배열의 길이, 즉 indices.length 여야합니다. –