le humble skybox
This commit is contained in:
parent
fed15e4ff8
commit
9162b9327e
Binary file not shown.
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 24 KiB |
Binary file not shown.
Before Width: | Height: | Size: 35 KiB After Width: | Height: | Size: 28 KiB |
|
@ -33,8 +33,8 @@ void renderInit(GLFWwindow* window) {
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
skyboxTexture = new Skybox({
|
skyboxTexture = new Skybox({
|
||||||
"assets/textures/skybox/null_plainsky512_rt.jpg",
|
|
||||||
"assets/textures/skybox/null_plainsky512_lf.jpg",
|
"assets/textures/skybox/null_plainsky512_lf.jpg",
|
||||||
|
"assets/textures/skybox/null_plainsky512_rt.jpg",
|
||||||
"assets/textures/skybox/null_plainsky512_up.jpg",
|
"assets/textures/skybox/null_plainsky512_up.jpg",
|
||||||
"assets/textures/skybox/null_plainsky512_dn.jpg",
|
"assets/textures/skybox/null_plainsky512_dn.jpg",
|
||||||
"assets/textures/skybox/null_plainsky512_ft.jpg",
|
"assets/textures/skybox/null_plainsky512_ft.jpg",
|
||||||
|
@ -47,6 +47,7 @@ void renderInit(GLFWwindow* window) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderParts() {
|
void renderParts() {
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
// Use shader
|
// Use shader
|
||||||
shader->use();
|
shader->use();
|
||||||
|
@ -101,12 +102,14 @@ void renderParts() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSkyBox() {
|
void renderSkyBox() {
|
||||||
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
skyboxShader->use();
|
skyboxShader->use();
|
||||||
|
|
||||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
||||||
// Remove translation component of view, making us always at (0, 0, 0)
|
// Remove translation component of view, making us always at (0, 0, 0)
|
||||||
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
|
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
|
||||||
|
|
||||||
skyboxShader->set("projection", projection);
|
skyboxShader->set("projection", projection);
|
||||||
skyboxShader->set("view", view);
|
skyboxShader->set("view", view);
|
||||||
|
|
||||||
|
@ -121,5 +124,5 @@ void render(GLFWwindow* window) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
renderSkyBox();
|
renderSkyBox();
|
||||||
// renderParts();
|
renderParts();
|
||||||
}
|
}
|
|
@ -8,15 +8,6 @@ Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
||||||
glGenTextures(1, &this->ID);
|
glGenTextures(1, &this->ID);
|
||||||
glBindTexture(GL_TEXTURE_CUBE_MAP, this->ID);
|
glBindTexture(GL_TEXTURE_CUBE_MAP, this->ID);
|
||||||
|
|
||||||
// Wrapping
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Interpolation
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
// stbi_set_flip_vertically_on_load(true);
|
// stbi_set_flip_vertically_on_load(true);
|
||||||
for (unsigned int i = 0; i< faces.size(); i++) {
|
for (unsigned int i = 0; i< faces.size(); i++) {
|
||||||
int width, height, nrChannels;
|
int width, height, nrChannels;
|
||||||
|
@ -30,11 +21,17 @@ Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
||||||
|
|
||||||
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format,
|
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, format, width, height, 0, format,
|
||||||
GL_UNSIGNED_BYTE, data);
|
GL_UNSIGNED_BYTE, data);
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
|
|
||||||
|
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrapping
|
||||||
|
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);
|
||||||
|
|
||||||
|
// Interpolation
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
Skybox::~Skybox() {
|
Skybox::~Skybox() {
|
||||||
|
|
Loading…
Reference in a new issue