I've recently learned how to texture in OpenGL. What I've been doing is something like this:
GLfloat vertexdata = {
-1.0f, -1.0f, 0.0f, 0.0, 0.0, //first three are xyz, next two are tex coords
0.0f, 1.0f, 0.0f, 0.5f, 1.0f,
...
};
Then I buffer this into the gpu, create/buffer indices, and create a VAO obj and draw with glDrawElements
. Now this worked great for things like triangles or squares, the problem is now I'm trying to draw a cube. For some reason, this is no londer working correctly. Why is that?
vertex data:
static GLfloat data[] = {
0.5f, 0.5f, 0.5f, 1.0f, 1.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f,
0.5f, 0.5f, -0.5f, 1.0f, 1.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f,
};
static GLuint indices[] = {
0, 1, 2, 3, 2, 0, //front face
0, 4, 1, 4, 5, 1, //right face
3, 2, 7, 2, 6, 7, //left face
4, 5, 6, 7, 6, 4, //back face
3, 7, 0, 0, 4, 7, //top face
2, 1, 5, 2, 6, 5, //bottom face
};
The following image shows the result (I intended for the batman logo to appear once once on each face sorta like this: http://learnopengl.com/img/getting-started/textures_combined2.png )