Я понимаю, что это очень простой вопрос, но я в растерянности, потому что я новичок в Java, новичок в разработке под Android, но у меня сильный опыт работы с C / C ++, с рабочим кодом в OpenGL, который мне нравится. Я пытаюсь здесь.
Я взял базовые примеры кода Cube.java и CubeRenderer.java и изменил их, добавив в них данные для икосаэдра. Я хочу использовать float вместо fixed, но я не знаю, возможно ли это или как это сделать.
Может кто-нибудь показать мне, что я делаю не так? Он компилируется и запускается без ошибок, но показывает только черноту. Другие алгоритмы рисования в Cube () такие же. Я попытался уменьшить размер pon (положительное значение 1,0), mon (минус 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;
}