简体   繁体   中英

Faces with different resolutions in GL_TEXTURE_CUBE_MAP

I've created a Cube in openGl and I need to provide 6 textures with different resolutions each other. Currently I'm using glTexImage2D to provide textures with same resolution, but obviously cannot be used for my new purpose.

The following code is something similar to what I did to have each face with the same resolution (just luminance channel):

glGenTextures(3, m_cubemapTexture);
glPixelStorei(GL_UNPACK_ROW_LENGTH, cube_size);

glBindTexture(GL_TEXTURE_CUBE_MAP, m_cubemapTexture[0]);

for (int face = 0; face < 6 face++){    
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, GL_LUMINANCE, cube_size, cube_size, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_uYdata[face]);
}

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);

glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

Edit

I think that the use of mipmap is not the right way because I can not simply downsample the texture with higher resolution. If I just change the width and the hight in the glTexImage2D() for the higher resolution texture the cube disappears.

Can you suggest how can I change the code?

6 textures with different resolutions each other

That's not allowed in cubemaps. Each cubemap face must have the same size. And must be a square (though not necessarily a power-of-two).

Otherwise the texture will not be considered complete and therefore uses of it will fail to access data. Hence the disappearing.

It is required that all those faces use this full size texture without downscaling them.

Then upscale the other faces.

I've created a Cube in openGl

If all you're doing is drawing a cube, you don't need to use a cubemap. Despite the name, displaying cubes is not what cubemap textures are for.

For your needs, all you have to do is use regular 2D texture mapping, with each face assigned to a region of a regular 2D texture. Each of the 6 "faces" you receive should be copied into those corresponding areas of the 2D texture. Thus, each face of the cube will display its particular region of the 2D texture.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM