13 if (cubemap_texture_ != 0) glDeleteTextures(1, &cubemap_texture_);
17 if (cubemap_texture_ != 0) {
18 glDeleteTextures(1, &cubemap_texture_);
20 cubemap_texture_ = load_cubemap(faces);
25 glGenTextures(1, &textureID);
26 glBindTexture(GL_TEXTURE_CUBE_MAP, textureID);
28 stbi_set_flip_vertically_on_load(
false);
29 int width, height, nrChannels;
30 for (uint32_t i = 0; i < faces.size(); i++) {
31 unsigned char *data = stbi_load(faces[i].c_str(), &width, &height, &nrChannels, 0);
33 GLenum format = (nrChannels == 3) ? GL_RGB : GL_RGBA;
34 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
35 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
36 stbi_image_free(data);
38 std::cout <<
"cubemaps texture failed to load at path: " << faces[i] << std::endl;
39 stbi_image_free(data);
43 stbi_set_flip_vertically_on_load(
false);
45 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
46 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
47 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
48 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
49 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
uint32_t load_cubemap(const std::array< std::string, 6 > &faces)
void set_cubemap_faces(const std::array< std::string, 6 > &faces)