A skybox that actually renders!
This commit is contained in:
parent
a9a7422a19
commit
fed15e4ff8
|
@ -1,15 +1,16 @@
|
|||
#version 330 core
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform samplerCube skybox;
|
||||
|
||||
in vec3 vPos;
|
||||
in vec3 vNormal;
|
||||
in vec2 vTexCoords;
|
||||
// in vec3 vPos;
|
||||
// in vec3 vNormal;
|
||||
in vec3 vTexCoords;
|
||||
|
||||
out vec4 fColor;
|
||||
|
||||
// Main
|
||||
|
||||
void main() {
|
||||
fColor = texture(uTexture, vTexCoords);
|
||||
// fColor = texture(uTexture, vTexCoords);
|
||||
fColor = texture(skybox, vTexCoords);
|
||||
}
|
||||
|
|
|
@ -3,17 +3,15 @@ layout (location = 0) in vec3 aPos;
|
|||
layout (location = 1) in vec3 aNormal;
|
||||
layout (location = 2) in vec2 aTexCoords;
|
||||
|
||||
out vec3 vPos;
|
||||
out vec3 vNormal;
|
||||
out vec2 vTexCoords;
|
||||
// out vec3 vPos;
|
||||
// out vec3 vNormal;
|
||||
out vec3 vTexCoords;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
void main()
|
||||
{
|
||||
vTexCoords = aPos;
|
||||
gl_Position = projection * view * vec4(aPos, 1.0);
|
||||
vPos = vec3(vec4(aPos, 1.0));
|
||||
vNormal = aNormal;
|
||||
vTexCoords = aTexCoords;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <GL/gl.h>
|
||||
#include <cstdio>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/trigonometric.hpp>
|
||||
|
@ -13,6 +14,7 @@
|
|||
#include "defaultmeshes.h"
|
||||
#include "../camera.h"
|
||||
#include "../part.h"
|
||||
#include "skybox.h"
|
||||
#include "texture.h"
|
||||
|
||||
#include "renderer.h"
|
||||
|
@ -21,7 +23,7 @@ Shader *shader = NULL;
|
|||
Shader *skyboxShader = NULL;
|
||||
extern Camera camera;
|
||||
extern std::vector<Part> parts;
|
||||
Texture* skyboxTexture = NULL;
|
||||
Skybox* skyboxTexture = NULL;
|
||||
|
||||
void renderInit(GLFWwindow* window) {
|
||||
glViewport(0, 0, 1200, 900);
|
||||
|
@ -30,7 +32,14 @@ void renderInit(GLFWwindow* window) {
|
|||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
skyboxTexture = new Texture("assets/textures/skybox/null_plainsky512_ft.jpg", GL_RGB);
|
||||
skyboxTexture = new Skybox({
|
||||
"assets/textures/skybox/null_plainsky512_rt.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_lf.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_up.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_dn.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_ft.jpg",
|
||||
"assets/textures/skybox/null_plainsky512_bk.jpg",
|
||||
}, GL_RGB);
|
||||
|
||||
// Compile shader
|
||||
shader = new Shader("assets/shaders/phong.vs", "assets/shaders/phong.fs");
|
||||
|
@ -95,7 +104,9 @@ void renderSkyBox() {
|
|||
skyboxShader->use();
|
||||
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.f), (float)1200 / (float)900, 0.1f, 100.0f);
|
||||
glm::mat4 view = camera.getLookAt();
|
||||
// Remove translation component of view, making us always at (0, 0, 0)
|
||||
glm::mat4 view = glm::mat4(glm::mat3(camera.getLookAt()));
|
||||
|
||||
skyboxShader->set("projection", projection);
|
||||
skyboxShader->set("view", view);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include "skybox.h"
|
||||
|
||||
Skybox::Skybox(std::vector<std::string> faces, unsigned int format) {
|
||||
Skybox::Skybox(std::array<std::string, 6> faces, unsigned int format) {
|
||||
glGenTextures(1, &this->ID);
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, this->ID);
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#define GL_RGB 0x1907
|
||||
|
@ -8,7 +9,7 @@ class Skybox {
|
|||
private:
|
||||
unsigned int ID;
|
||||
public:
|
||||
Skybox(std::vector<std::string>, unsigned format = GL_RGB);
|
||||
Skybox(std::array<std::string, 6>, unsigned format = GL_RGB);
|
||||
~Skybox();
|
||||
|
||||
void activate(unsigned int textureIdx);
|
||||
|
|
Loading…
Reference in a new issue