I'm studying LWJGL3 with '3D Game Development with LWJGL3', and I made a textured cube as reading the Chapter7 of the book.
However, I was so puzzled after seeing my cube. The cube was distorted. Could you tell me why my cube is rendered oddly?
// This is the VAO of the cube.
float[] positions = new float[]{
-0.5f, 0.5f, 0.5f, // V0
-0.5f, -0.5f, 0.5f, // V1
0.5f, -0.5f, 0.5f, // V2
0.5f, 0.5f, 0.5f, // V3
-0.5f, 0.5f, -0.5f, // V4
0.5f, 0.5f, -0.5f, // V5
-0.5f, -0.5f, -0.5f, // V6
0.5f, -0.5f, -0.5f, // V7
// Top 4503
-0.5f, 0.5f, -0,5f, // V8
0.5f, 0.5f, -0.5f, // V9
-0.5f, 0.5f, 0.5f, // V10
0.5f, 0.5f, 0.5f, // V11
// Right 3 2
0.5f, 0.5f, 0.5f, // V12
0.5f, -0.5f, 0.5f, // V13
// Left 0 1
-0.5f, 0.5f, 0.5f, // V14
-0.5f, -0.5f, 0.5f, // V15
// BOTTOM 6712
-0.5f, -0.5f, -0.5f, // V16
0.5f, -0.5f, -0.5f, // V17
-0.5f, -0.5f, 0.5f, // V18
0.5f, -0.5f, 0.5f, // V19
};
float[] textCoords = new float[] {
0.0f, 0.0f,
0.0f, 0.5f,
0.5f, 0.5f,
0.5f, 0.0f,
0.0f, 0.0f,
0.5f, 0.0f,
0.0f, 0.5f,
0.5f, 0.5f,
// Top
0.0f, 0.5f,
0.5f, 0.5f,
0.0f, 1.0f,
0.5f, 1.0f,
// Right
0.0f, 0.0f,
0.0f, 0.5f,
// Left
0.5f, 0.0f,
0.5f, 0.5f,
// Bottom
0.5f, 0.0f,
1.0f, 0.0f,
0.5f, 0.5f,
1.0f, 0.5f,
};
int[] indices = new int[] {
// Front
0, 1, 3, 3, 1, 2,
// Top
8, 10, 11, 9, 8, 11,
// Right
12, 13, 7, 5, 12, 7,
// Left
14, 15, 6, 4, 14, 6,
// Bottom
16, 18, 19, 17, 16, 19,
// Back
4, 6, 7, 5, 4, 7,
};
[Result]
https://imgur.com/a/HicRN[When I rendered only front face]
https://imgur.com/a/gCjBo[Source code]
* Check Attachment
I don't have any idea about how I can solve this problem.
Please help me. X(