PDA

View Full Version : Cubemap: No colour is obtained on calling textureCube



ZehreMor
05-07-2012, 09:48 AM
Here is my Vertex Shader:

#version 400


layout(location=0) in vec4 in_Position;
layout(location=1) in vec4 in_Color;
layout(location=2) in vec3 in_Vertex_Normal;
layout(location=3) in vec3 in_Tex_Posn;
out vec3 ReflectDir;
vec3 FragNormal;
vec4 FragPosition;


uniform mat4 ModelMatrix;
uniform mat4 ViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 MVMatrixInvTrans;
uniform vec3 WorldCameraPosition;


void main(void)
{
FragNormal = vec3(MVMatrixInvTrans * vec4(in_Vertex_Normal, 0.0));
FragPosition = vec4(ViewMatrix * ModelMatrix * in_Position);

vec4 cameraPosn = vec4(ViewMatrix * vec4(WorldCameraPosition, 1.0));
vec3 worldView = vec3( a - FragPosition );
ReflectDir = reflect(-worldView, FragNormal );

gl_Position = (ProjectionMatrix * ViewMatrix * ModelMatrix) * in_Position;
}

And this is the Fragment Shader:

#version 400


in vec3 ReflectDir;
out vec4 out_Color;
uniform samplerCube CubeMapTex;

void main(void)
{
vec3 cubeMapColor = textureCube(CubeMapTex,ReflectDir);
out_Color = vec4(cubeMapColor,1.0) ;
}

Now here is the code which sets the texture configurations:

glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &image); /* Texture name generation */
glBindTexture(GL_TEXTURE_CUBE_MAP, image); /* Binding of texture name */
const char* suffixes[] = { "posx", "negx", "posy",
"negy", "posz", "negz" };
GLuint targets[] = {GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z };
char* baseName = "C:\\cubemap\\museum_";

for(int i = 0; i < 6; i++)
{
string texName = string(baseName) + suffixes[i] + ".png";
ilInit(); /* Initialization of DevIL */
ilGenImages(1, &texid); /* Generation of one image name */
ilBindImage(texid); /* Binding of image name */
bool success = ilLoadImage((const ILstring)texName.c_str()); /* Loading of image "image.jpg" */
if(success)
{
success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
glTexImage2D(targets[i], 0, GL_RGBA, ilGetInteger(IL_IMAGE_WIDTH),
ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
ilGetData()); /* Texture specification */
ExitOnGLError("ERROR: glTexImage2D");
ilDeleteImages(1, &texid);
}
else
cout << "\n Failed to load image --" << i << endl;
}


glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);


// Set the CubeMapTex uniform to texture unit 0
CubeMapTexUniLoc = glGetUniformLocation(ShaderIds[0], "CubeMapTex");


And finally here is the piece of code which is called when rendering:

glBindVertexArray(BufferIds[0]);
ExitOnGLError("ERROR: Could not bind the VAO for drawing purposes");
glActiveTexture(GL_TEXTURE0);

glBindTexture(GL_TEXTURE_CUBE_MAP, image); /* Binding of texture name */
glDrawElements(GL_TRIANGLES, sizeof(INDICES), GL_UNSIGNED_INT, (GLvoid*)0);
ExitOnGLError("ERROR: Could not draw the cube");
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
glBindVertexArray(0);


Also this is how the sampleCube is set:
glUniform1i(CubeMapTexUniLoc, 0);
ExitOnGLError("ERROR: Could not set the shader uniforms -- Sampler cube map");

I get no colour at all on the object.
I know this topic has been asked as recently as 2nd May 2012 on this forum but there was no resolution to that question hence I am asking again.