# Texture errors in CubeMap

I am trying to apply this texture as a cubemap. This is my result:

Clearly I am doing something with my texture coordinates, but I cannot for the life of me figure out what. I don't even see a pattern to the texture fragments. They just seem like a jumble of different faces. Can anyone shed some light on this?

#version 400
in  vec4 vPosition;
in  vec3 inTexCoord;

smooth out vec3 texCoord;

uniform mat4 projMatrix;

void main()
{
texCoord = inTexCoord;
gl_Position = projMatrix * vPosition;
}


#version 400
smooth in vec3 texCoord;

out vec4 fColor;

uniform samplerCube textures

void main()
{
fColor = texture(textures,texCoord);
}


Vertices of cube:

point4 worldVerts[8] = {
vec4(  15,  15,  15, 1 ),
vec4( -15,  15,  15, 1 ),
vec4( -15,  15, -15, 1 ),
vec4(  15,  15, -15, 1 ),
vec4( -15, -15,  15, 1 ),
vec4(  15, -15,  15, 1 ),
vec4(  15, -15, -15, 1 ),
vec4( -15, -15, -15, 1 )
};


Cube rendering:

void
worldCube(point4* verts, int& Index, point4* points, vec3* texVerts)
{

quadInv( verts[0], verts[1], verts[2], verts[3], 1, Index, points, texVerts);
quadInv( verts[6], verts[3], verts[2], verts[7], 2, Index, points, texVerts);
quadInv( verts[4], verts[5], verts[6], verts[7], 3, Index, points, texVerts);
quadInv( verts[4], verts[1], verts[0], verts[5], 4, Index, points, texVerts);
quadInv( verts[5], verts[0], verts[3], verts[6], 5, Index, points, texVerts);
quadInv( verts[4], verts[7], verts[2], verts[1], 6, Index, points, texVerts);
}


Backface function (since this is the inside of the cube):

void quadInv( const point4& a, const point4& b, const point4& c, const point4& d ,
int& Index, point4* points, vec3* texVerts)

{
quad( a, d, c, b, Index, points, texVerts, a.to_3(), d.to_3(), c.to_3(), b.to_3());
}


And the quad drawing function:

void quad( const point4& a, const point4& b, const point4& c, const point4& d,
int& Index, point4* points, vec3* texVerts, const vec3& tex_a, const vec3& tex_b, const vec3& tex_c, const vec3& tex_d)

{
texVerts[Index] = tex_a.normalized(); points[Index] = a; Index++;
texVerts[Index] = tex_b.normalized(); points[Index] = b; Index++;
texVerts[Index] = tex_c.normalized(); points[Index] = c; Index++;
texVerts[Index] = tex_a.normalized(); points[Index] = a; Index++;
texVerts[Index] = tex_c.normalized(); points[Index] = c; Index++;
texVerts[Index] = tex_d.normalized(); points[Index] = d; Index++;
}


Edit: I forgot to mention, in the image, the camera is pointed directly at the back face of the cube. You can kind of see the diagonals leading out of the corners, if you squint.

I tried writing the texture coordinates as colors as Nathan Reed suggested, and still got random values from the fragment shader, so I tried replacing all texture coordinates with (0,1,0) (so as colors, all faces should be green). Instead, I got this:

Old result with b and d vertices swapped in texture:

• Please post your vertex shader too – Maximus Minimus Oct 29 '13 at 23:17
• Vertex shader now included. – shade4159 Oct 29 '13 at 23:28
• When calling quad you've got a, d, c, b for the points but a, b, c, d for the texture coordinates. That looks suspicious. – Nathan Reed Oct 29 '13 at 23:29
• Whoops! Thanks, fixed that, updated code and resulting image. – shade4159 Oct 30 '13 at 11:54
• You might try editing your pixel shader to write fColor = normalize(texCoord) * 0.5 + 0.5; - this will visualize the vectors directly as RGB colors, so it should be easier for you to see what's going wrong. E.g. the +X side of the cube should have a high red component and the -X side should not, etc. – Nathan Reed Oct 30 '13 at 18:25

• Glad you got it working! Viewing vectors as colors is a quite handy trick for shader debugging, useful in all sorts of situations. And the size-4 thing is probably related to the memory layout of your vectors - I suppose vec3 is 16 bytes long instead of 12. – Nathan Reed Oct 31 '13 at 5:04