Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Cube Mapping OpenGl ES

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    6

    Cube Mapping OpenGl ES


    Im having some trouble whit the 6 tga faces for my cube, i cant see the image cleary in the face, I just see kind of like the color of the tga but no the image clearly. I load the cube from an obj model, I ve been using different models of cube.obj with diferent texture coords ant still the same result.
    Then I realize that the cube is just like takin the negative X and positive Y images, and expanding them all over the cube and not even well just like the color of the tga.

    Here is part of my code





    U5.Loc = glGetUniformLocation ( U5.programObject, "u_s_texture" );

    U5.TexId =Cubemap ("pos_x.tga","pos_y.tga","pos_z.tga","neg_x.tga"," neg_y.tga","neg_z.tga");


    GLuint Cubemap( char *PX,char*PY, char *PZ,char *NX,char*NY, char *NZ)
    {
    GLuint textureId;
    int width,
    height;
    int width2,
    height2;
    int width3,
    height3;
    int width4,
    height4;
    int width5,
    height5;
    int width6,
    height6;

    char *BPX = esLoadTGA ( PX, &width, &height );
    char *BPY = esLoadTGA ( PY, &width2, &height2 );
    char *BPZ = esLoadTGA ( PZ, &width3, &height3 );
    char *BNX = esLoadTGA ( NX, &width4, &height4 );
    char *BNY = esLoadTGA ( NY, &width5, &height5 );
    char *BNZ = esLoadTGA ( NZ, &width6, &height6 );
    GLuint texId;

    if ( BPX == NULL || BPY == NULL || BPZ == NULL || BNX == NULL ||BNY == NULL || BNZ == NULL )
    {
    esLogMessage ( "Error loading (%s) image.\n", PX );
    system("pause");
    return 0;
    }
    // Generate a texture object
    glGenTextures ( 1, &textureId );

    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    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);

    // Bind the texture object
    glBindTexture ( GL_TEXTURE_CUBE_MAP, textureId );
    // for ( q=0;q<6;q++){
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_R GB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BPX);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_R GB,width4,height4,0,GL_RGB,GL_UNSIGNED_BYTE,BNX);//---
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_R GB,width2,height2,0,GL_RGB,GL_UNSIGNED_BYTE,BPY);//**
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_R GB,width5,height5,0,GL_RGB,GL_UNSIGNED_BYTE,BNY);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_R GB,width3,height3,0,GL_RGB,GL_UNSIGNED_BYTE,BPZ);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_R GB,width6,height6,0,GL_RGB,GL_UNSIGNED_BYTE,BNZ);
    //}
    glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);



    GLbyte vShaderStr[] =
    "uniform mat4 u_mvpMatrix; \n"
    "attribute vec4 a_position; \n"
    "attribute vec4 a_texCoord; \n"
    "varying vec4 v_pos; \n"
    "void main() \n"
    "{ \n"
    " gl_Position = u_mvpMatrix * a_position; \n
    " v_pos = a_texCoord; \n"
    "} \n";

    GLbyte fShaderStr[] =
    "precision mediump float; \n"
    "varying vec2 v_texCoord; \n"
    "uniform sampler2D s_betty; \n"
    "varying vec4 v_pos; \n"
    "uniform samplerCube u_s_texture; \n"
    "void main() \n"
    "{ \n"
    " gl_FragColor=textureCube(u_s_texture, v_pos.xyz); \n"
    "} \n";

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: Cube Mapping OpenGl ES

    Please use [ code]/[ /code] (without space after '[') around code snippets to make them easier to read.

    Cube textures require 3 component texture coordinates, because they are meant for cases where you do a texture lookup based on a direction (e.g. environment mapping). Your model files probably only contain the usual 2 component texture coordinates which don't work for cube textures.
    If you want to map a different texture to each face of a cube you need to split the cube into 6 different objects (so that you can switch textures between draw calls), combine your textures into one (texture atlas, texture array, cube texture) and adjust the texture coordinates.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    6

    Re: Cube Mapping OpenGl ES

    sorry for the code, so you are telling me that I need 3 components for the texture coordinates, and also divide the the cube.obj in six parts?...While I was looking for cubes with six different faces I only see two components in the coordinates and their examples seems to work.
    I dont understand why i need to split in 6 parts also.

    I`ve been looking for a 3 components texture cube obj, and I can't found can you lead to an example?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Cube Mapping OpenGl ES

    I can't quite figure out if you are trying to implement 'cube mapping' or just loading a OBJ file which happens to be a cube.

    If we are talking about 'cube mapping' then you don't need any texture coordinates from the OBJ model. The Vertex Shader will compute texture coordinates based on your eye-space vertex positions.

    Secondly, the loading of the 6 faces can be simplified by ensuring all texture dimensions are exactly the same for each face. Thus there is no need for width2,3,4,5,6 as all are the same.

    Finally,
    glBindTexture ( GL_TEXTURE_CUBE_MAP, textureId );
    ...
    glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    It looks like you are using cube mapping by the virtue of binding a cube map texture. You then generate mipmaps for it but you have mistakenly used only GL_LINEAR as the minification filter. It should be GL_LINEAR_MIPMAP_LINEAR.

  5. #5
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    6

    Re: Cube Mapping OpenGl ES

    I cant understand the difference Im trying to make an skybox, but I load the cube from a obj model..i take the suggestions and now i only see one color in the cube, not even quite the texture as before when i use texture coords.

    Code :
     
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BPX); 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BNX);//--- 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BPY);//** 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BNY); 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BPZ); 
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGB,width,height,0,GL_RGB,GL_UNSIGNED_BYTE,BNZ);
     
       glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR );
       glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
       glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR );
       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 );
     
    /

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Cube Mapping OpenGl ES

    glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR
    No, only the minification filter uses mipmaps.
    The magnification filter is just LINEAR.
    glTexParameteri ( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER,GL_LINEAR);

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    6

    Re: Cube Mapping OpenGl ES

    Already change it, and the same result, any other tip, i just see one color now in all the cube, all my 6 tga are the same size and I think everything its ok.

  8. #8
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Cube Mapping OpenGl ES

    I don't see you Vertex Shader anywhere.
    I'm assuming you have set the pass-through texture coordinates in the Vertex shader = gl_Vertex.xyz ?

  9. #9
    Junior Member Newbie
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    6

    Re: Cube Mapping OpenGl ES

    Isnt here what you are talking...?



    Code :
    GLbyte vShaderStr[] =
    "uniform mat4 u_mvpMatrix; \n"
    "attribute vec4 a_position; \n"
    "attribute vec4 a_texCoord; \n"
    "varying vec4 v_pos; \n"
    "void main() \n"
    "{ \n"
    " gl_Position = u_mvpMatrix * a_position; \n
    " v_pos = a_texCoord; \n"
    "} \n";
     
    GLbyte fShaderStr[] =
    "precision mediump float; \n"
    "varying vec2 v_texCoord; \n"
    "uniform sampler2D s_betty; \n"
    "varying vec4 v_pos; \n"
    "uniform samplerCube u_s_texture; \n"
    "void main() \n"
    "{ \n"
    " gl_FragColor=textureCube(u_s_texture, v_pos.xyz); \n"
    "} \n";
    /

  10. #10
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Cube Mapping OpenGl ES

    so it is....
    In that case, just change the VS to:
    Code :
    GLbyte vShaderStr[] =
    "uniform mat4 u_mvpMatrix; \n"
    "attribute vec4 a_position; \n"
    "attribute vec4 a_texCoord; \n"
    "varying vec4 v_pos; \n"
    "void main() \n"
    "{ \n"
    " gl_Position = u_mvpMatrix * a_position; \n
    " v_pos = a_position; \n"
    "} \n";

Page 1 of 2 12 LastLast

Similar Threads

  1. Some Bump Mapping Questions (cube-mapping)
    By Whooster in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-14-2012, 11:55 PM
  2. Cube Mapping Using OpenGL
    By someoney in forum OpenGL: Basic Coding
    Replies: 11
    Last Post: 12-19-2010, 12:53 AM
  3. Cube Map without using OpenGL's Cube Mapping
    By someoney in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-10-2010, 01:05 PM
  4. Cube Mapping
    By phlake in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 04-14-2002, 10:33 PM
  5. NVidia OpenGL SDK && Cube Environment Mapping
    By KRONOS in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-13-2001, 05:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean