Hello Guest

# [Solved] Could you tell me why textured cube is rendered oddly?

• 2 Replies
• 823 Views

#### Harang

• 3
##### [Solved] Could you tell me why textured cube is rendered oddly?
« on: January 12, 2018, 07:24:31 »
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.
« Last Edit: January 13, 2018, 00:46:11 by Harang »

#### BrickFarmer

• 106
##### Re: Could you tell me why textured cube is rendered oddly?
« Reply #1 on: January 12, 2018, 20:06:25 »
You just have a comma where you need a stop:

-0.5f, 0.5f, -0,5f,    // V8
goes to:
-0.5f, 0.5f, -0.5f,    // V8

Oh and welcome to the LWJGL forum
Oculus Rift CV1, MBP 2016 - 2.9 i7 - Radeon Pro 460  OSX 10.12.4,  Win7 - i5 4670K - GTX1070.
Oculus Rift VR Experiments: https://github.com/WhiteHexagon

#### Harang

• 3
##### Re: Could you tell me why textured cube is rendered oddly?
« Reply #2 on: January 13, 2018, 00:45:35 »
You just have a comma where you need a stop:

-0.5f, 0.5f, -0,5f,    // V8
goes to:
-0.5f, 0.5f, -0.5f,    // V8

Oh and welcome to the LWJGL forum

I guessed that my code had several differences compared with a example code, but I didn't know that the problem was very simple like this.
The foot of the candle was dark. Thank you so much!