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: Passing cubemap as a parameter for my fragment shader

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    1

    Passing cubemap as a parameter for my fragment shader

    I am extremely confused about how to pass a cube map texture into my fragment Program.

    Here is the code I used to create the cube map.

    Code :
    glEnableClientState(GL_TEXTURE_CUBE_MAP);
     
    		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, envmap->right->w, 
    			envmap->right->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->right->pix);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, envmap->left->w, 
    			envmap->left->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->left->pix);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, envmap->top->w, 
    			envmap->top->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->top->pix);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, envmap->front->w, 
    			envmap->front->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->bottom->pix);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, envmap->front->w, 
    			envmap->front->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->back->pix);
     
    		glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, envmap->front->w, 
    			envmap->front->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, envmap->front->pix);
     
     
    		glBindTexture(GL_TEXTURE_CUBE_MAP, 1);
    		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
     
    		glEnable(GL_TEXTURE_CUBE_MAP);

    Then, where I do my per-frame initialization for my shader, I have the following code
    Code :
    fragmentCubeMap = cgGetNamedParameter(fragmentProgram, "cubemap");
    cgGLSetTextureParameter(fragmentCubeMap, 1);
      cgGLEnableTextureParameter(fragmentCubeMap);

    where I need to replace '1' in the call to cgGLSetTextureParameter() with whatever value will give me the cube map I'm building in the previous block of code.
    Then the function header for my shader looks like this
    Code :
    PixelDataOutput FragmentMain(VertexDataOutput pdi, 
    	uniform float blueHue, uniform float3 lightDirv, uniform float3 ppcC, uniform float blendfactor,
    	uniform float canvasFlag, uniform samplerCUBE cubemap) {
    Where cubemap is, of course, my samplerCUBE object.

    Right now, when I run what I have, the samplerCUBE is actually giving me some default information. Each face of the cube is just a different color, but it has nothing to do with the maps that I actually specified in the glTexImage2D() calls in first block of code. I suspect that the magic happens somewhere near glBindTexture();. I think I'm making it pretty obvious from this post that I'm in way over my head, but I need to do this somehow, so any help would be greatly appreciated.

  2. #2
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    1. This is an invalid call

    glEnableClientState(GL_TEXTURE_CUBE_MAP)

    I suggest that you use glGetError() to detect such problems.

    2. I suggest that you use glGenTextures to get a texture ID. Then call glBindTexture and then setup your texture.
    3. There is no need to call glTexEnvi. It does nothing when you are using shaders.
    4. There is no need to call glEnable(GL_TEXTURE_CUBE_MAP). It does nothing when you are using shaders.
    ------------------------------
    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
  •