Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Cubemap texture not shown

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2012
    Posts
    5

    Cubemap texture not shown

    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:
    Code :
    //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:
    Code :
    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:
    Code :
    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
    Last edited by jiaoyang_28; 05-02-2012 at 11:55 AM.

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421
    You need to make sure that your object has normals since your texcoords depend on it.
    Does lighting look ok in fixed function mode?

    Did you call glGetError()?

    BTW, a bunch of those calls have no effect if you are using shaders such as
    glEnable(GL_TEXTURE_CUBE_MAP);
    and the TexGen calls.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •