Hi,
This problem is bugging for days. I just can not find why my cubemap is not shown on the object.
I draw a sphere, and I want to wrap it with the cube map.
The following is my code in opengl:
//replace the car to a ball
quadratic=gluNewQuadric();
gluQuadricOrientation(quadratic, GLU_OUTSIDE);
gluQuadricNormals(quadratic, GLU_SMOOTH);
gluQuadricTexture(quadratic, GL_TRUE);
static unsigned *imagec[6];
static int widthc[6], heightc[6], componentsc[6];
GLenum cuben[6] = { 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* filename[6] = {"../image/road.rgb","../image/road.rgb","../image/street_sky.rgb","../image/street_ground.rgb","../image/street_front.rgb","../image/street_front.rgb"};
GLuint textureNum[1];
glGenTextures(1, textureNum);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureNum[0]);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//load the textures
for(i = 0; i < 6; i++)
{
imagec[i] = read_texture(filename[i], &widthc[i], &heightc[i], &componentsc[i]);
glTexImage2D(cuben[i], 0, GL_RGB, widthc[i], heightc[i], 0, GL_RGBA, GL_UNSIGNED_BYTE, imagec[i]);
}
glEnable(GL_TEXTURE_CUBE_MAP);
glUseProgram(g);
GLint texLoc;
texLoc = glGetUniformLocation(g, "cube_texture");
glUniform1i(texLoc, 1);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
gluSphere(quadratic,0.25f,48,48);
gluQuadricTexture(quadratic,GLU_TRUE);
gluQuadricDrawStyle(quadratic,GLU_FILL);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
My vertex shader is:
varying vec3 R;
void main() {
vec3 N = normalize(gl_NormalMatrix * gl_Normal);
vec3 V = normalize(gl_Vertex.xyz);
vec3 L = normalize(gl_LightSource[0].position.xyz); //I setup the light pos in opengl init(), and enabled light0
R = reflect(V, N);
}
My fragment shader is:
uniform samplerCube cube_texture;
varying vec3 R;
void main() {
vec4 cubeC = textureCube(cube_texture, R);
gl_FragColor = cubeC;
}
Maybe I read the code for too many times, I just can not find out why my result object is just a gray ball.
Any hint would be warmly welcomed.
Thank you very much