Commit 0c1e2acd authored by Håkon Berg Borhaug's avatar Håkon Berg Borhaug
Browse files

Refactored stuff

parent e62037d2
......@@ -45,6 +45,7 @@ set( INCLUDE
include/VertexBufferLayout.h
include/Texture.h
include/Projection.h
include/Skybox.h
include/GLErrorHandler.h
include/stb_image.h
......@@ -63,6 +64,7 @@ set( SRCS
src/VertexArray.cpp
src/VertexBuffer.cpp
src/Texture.cpp
src/Skybox.cpp
src/GLErrorHandler.cpp
src/stb_image.cpp
......
......@@ -9,6 +9,7 @@
#include "Snow.hpp"
#include "Text.hpp"
#include "Minimap.hpp"
#include "Skybox.h"
#include <GL/gl.h>
#include <GL/glu.h>
......@@ -37,12 +38,15 @@ class GameManager : public SceneObject
std::shared_ptr<Plane> ls4_;
std::shared_ptr<Plane> ls5_;
std::shared_ptr<Plane> sbw_;
std::shared_ptr<Plane> sbn_;
std::shared_ptr<Plane> sbe_;
std::shared_ptr<Plane> sbs_;
std::shared_ptr<Plane> sbu_;
std::shared_ptr<Plane> sbd_;
// std::shared_ptr<Plane> sbw_;
// std::shared_ptr<Plane> sbn_;
// std::shared_ptr<Plane> sbe_;
// std::shared_ptr<Plane> sbs_;
// std::shared_ptr<Plane> sbu_;
// std::shared_ptr<Plane> sbd_;
std::shared_ptr<Skybox> sb_;
std::shared_ptr<Character> character_;
std::shared_ptr<Camera> cam_;
std::shared_ptr<Snow> snow_;
......
......@@ -15,14 +15,14 @@
#include "../../glm-master/glm/glm.hpp"
// 4 points with 3D position and 2D texture position
#define POS_ARRAY_SIZE 4 * (3 + 2)
#define IND_ARRAY_SIZE 4
#define LS_POS_ARRAY_SIZE 4 * (3 + 2)
#define LS_IND_ARRAY_SIZE 4
class Plane : public SceneObject
{
public:
Plane(glm::vec3 trans, std::string texturePath, glm::vec3 rotationAxis = glm::vec3(0.0f, 0.0f, 0.0f),
float rotationAngle = 0.0f, glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f), bool isFixed = false, bool isTilted = false);
Plane(glm::vec3 trans, glm::vec3 rotationAxis = glm::vec3(0.0f, 0.0f, 0.0f),
float rotationAngle = 0.0f, glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f));
~Plane();
protected:
......@@ -38,52 +38,26 @@ private:
// texture coord array
std::vector< glm::vec3 > textureArray_;
float positions_[POS_ARRAY_SIZE] = {
// -0.5f, -0.5f, 0.0f,
// 0.5f, -0.5f, 3.0f,
// 0.5f, 0.5f, 3.0f,
// -0.5f, 0.5f, 0.0f
float positions_[LS_POS_ARRAY_SIZE] = {
// Left plane
-100.0f,0.0f, 100.0f, 0.0f, 0.0f,
100.0f, 0.0f, 100.0f, 1.0f, 0.0f,
100.0f, 0.0f, -100.0f, 1.0f, 1.0f,
-100.0f,0.0f, -100.0f, 0.0f, 1.0f,
// // Middle plane
// 0.0f, -50.0f, 50.0f, 0.0f, 0.0f,
// 100.0f, -50.0f, 50.0f, 1.0f, 0.0f,
// 100.0f, -50.0f, -50.0f, 1.0f, 1.0f,
// 0.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// // Right plane
// 100.0f, -50.0f, 50.0f, 0.0f, 0.0f,
// 200.0f, -50.0f, 50.0f, 1.0f, 0.0f,
// 200.0f, -50.0f, -50.0f, 1.0f, 1.0f,
// 100.0f, -50.0f, -50.0f, 0.0f, 1.0f,
// // Background
// -1000.0f, -1000.0f, -500.0f, 0.0f, 0.0f,
// 1000.0f, -1000.0f, -500.0f, 1.0f, 0.0f,
// 1000.0f, 1000.0f, -500.0f, 1.0f, 1.0f,
// -1000.0f, 1000.0f, -500.0f, 0.0f, 1.0f,
};
unsigned int indices_[IND_ARRAY_SIZE] = {
unsigned int indices_[LS_IND_ARRAY_SIZE] = {
0, 1, 2, 3,
// 4, 5, 6, 7,
// 8, 9, 10, 11,
// 12, 13, 14, 15
};
VertexArray vao;
VertexBuffer vbo = VertexBuffer(positions_, POS_ARRAY_SIZE * sizeof(float));
VertexBuffer vbo = VertexBuffer(positions_, LS_POS_ARRAY_SIZE * sizeof(float));
VertexBufferLayout layout;
IndexBuffer ibo = IndexBuffer(indices_, IND_ARRAY_SIZE);
IndexBuffer ibo = IndexBuffer(indices_, LS_IND_ARRAY_SIZE);
Shader shader = Shader("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Vertex.shader",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Fragment.shader");
Texture texture; // = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg");
Texture texture = Texture("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg");
unsigned int textureSlot = 0;
bool fixed;
float scaling;
};
......@@ -3,6 +3,8 @@
#include <memory>
#include <vector>
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/type_ptr.hpp"
#include "../include/Projection.h"
// The SceneObject class is the parent of all objects in the scene graph.
// To make an object to use in the scene graph, inherit this class and
......@@ -72,6 +74,9 @@ class SceneObject
// View matrix
glm::mat4 viewMatrix_;
// Projection matrix
glm::mat4 projMatrix_ = glm::perspective(glm::radians(proj::PoV), proj::aspectRatio, proj::nearClip, proj::farClip);
private:
// List of all SceneObjects that belong to the current object.
std::vector<std::shared_ptr<SceneObject> > children_;
......
#pragma once
#include "../include/VertexArray.h"
#include "../include/VertexBuffer.h"
#include "../include/VertexBufferLayout.h"
#include "../include/IndexBuffer.h"
#include "../include/Shader.h"
#include "../include/Texture.h"
#include <windows.h>
#include <GL/freeglut.h>
#include <GL/glu.h>
#include <vector>
#include "SceneObject.hpp"
#include "../../glm-master/glm/glm.hpp"
// 4 points with 3D position and 2D texture position
#define SB_POS_ARRAY_SIZE 6 * 6 * 3
#define SB_IND_ARRAY_SIZE 6 * 6
class Skybox : public SceneObject
{
public:
Skybox();
~Skybox();
protected:
virtual void privateInit();
virtual void privateRender();
virtual void privateUpdate();
private:
float positions_[SB_POS_ARRAY_SIZE] = {
// Right face
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
// Left face
-1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
// Top face
-1.0f, 1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
// Bottom face
-1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
// North face
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
// South face
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, -1.0f, 1.0f,
};
unsigned int indices_[SB_IND_ARRAY_SIZE] = {
0, 1, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17,
18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35
};
VertexArray vao;
VertexBuffer vbo = VertexBuffer(positions_, SB_POS_ARRAY_SIZE * sizeof(float));
VertexBufferLayout layout;
IndexBuffer ibo = IndexBuffer(indices_, SB_IND_ARRAY_SIZE);
Shader shader = Shader("C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Skybox_vertex.shader",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/shaders/Skybox_fragment.shader");
std::vector<std::string> faceTextures{
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_east.bmp",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_west.bmp",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_up.bmp",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_down.bmp",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_north.bmp",
"C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_south.bmp"
};
Texture texture = Texture(faceTextures);
unsigned int textureSlot = 0;
};
......@@ -2,6 +2,8 @@
#include "GLErrorHandler.h"
#include <vector>
class Texture {
private:
unsigned int m_RendererID;
......@@ -10,11 +12,14 @@ private:
int m_Width, m_Height, m_BPP;
public:
Texture(const std::string& filepath);
Texture(const std::vector<std::string> faces);
~Texture();
void Bind(unsigned int slot = 0) const;
void BindCubemap(unsigned int slot = 0) const;
void Unbind() const;
void UnbindCubemap() const;
inline int GetWidth() const { return m_Width; }
inline int GetHeight() const { return m_Height; }
};
\ No newline at end of file
};
// FRAGMENT SHADER
#shader fragment
#version 330 core
layout(location = 0) out vec4 color;
in vec3 v_TexCoord;
//uniform vec4 u_Color;
uniform samplerCube u_Texture;
void main() {
vec4 texColor = texture(u_Texture, v_TexCoord);
color = texColor;
};
// VERTEX SHADER
#shader vertex
#version 330 core
layout(location = 0) in vec3 position;
out vec3 v_TexCoord;
uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ModelMatrix;
void main() {
gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(position, 1.0);
v_TexCoord = position;
};
......@@ -7,9 +7,11 @@ layout(location = 1) in vec2 texCoord;
out vec2 v_TexCoord;
uniform mat4 u_MVP;
uniform mat4 u_ProjectionMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ModelMatrix;
void main() {
gl_Position = u_MVP * position;
gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * position;
v_TexCoord = texCoord;
};
......@@ -26,49 +26,33 @@ void GameManager::privateInit()
cam_.reset(new Camera());
// Landscape
auto landscapeTexturePath = "C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/road.jpg";
auto landscapeSize = 200.0f;
auto landscapeScaling = 3.0f;
auto landscapeRealSize = landscapeSize * landscapeScaling;
ls1_.reset(new Plane(glm::vec3(0.0f, -50.0f, 0.0f), landscapeTexturePath, glm::vec3(0.0f, 0.0f, 1.0f),
30.0f, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
const auto landscapeSize = 200.0f;
const auto landscapeScaling = 3.0f;
const auto landscapeRealSize = landscapeSize * landscapeScaling;
const auto landscapeRotationAxis = glm::vec3(0.0f, 0.0f, 1.0f);
const auto landscapeRotationDegree = 30.0f;
const auto landscapeX = landscapeRealSize * cos(glm::radians(landscapeRotationDegree));
const auto landscapeY = landscapeRealSize * sin(glm::radians(landscapeRotationDegree));
ls1_.reset(new Plane(glm::vec3(0.0f, -50.0f, 0.0f), landscapeRotationAxis,
landscapeRotationDegree, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
this->addSubObject(ls1_);
ls2_.reset(new Plane(glm::vec3(landscapeRealSize * cos(glm::radians(30.0f)), -50.0f + landscapeRealSize * sin(glm::radians(30.0f)), 0.0f), landscapeTexturePath, glm::vec3(0.0f, 0.0f, 1.0f),
30.0f, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
ls2_.reset(new Plane(glm::vec3(landscapeX, -50.0f + landscapeY, 0.0f), landscapeRotationAxis,
landscapeRotationDegree, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
this->addSubObject(ls2_);
ls3_.reset(new Plane(glm::vec3(2 * landscapeRealSize * cos(glm::radians(30.0f)), -50.0f + 2 * landscapeRealSize * sin(glm::radians(30.0f)), 0.0f), landscapeTexturePath, glm::vec3(0.0f, 0.0f, 1.0f),
30.0f,glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
ls3_.reset(new Plane(glm::vec3(2 * landscapeX, -50.0f + 2 * landscapeY, 0.0f), landscapeRotationAxis,
landscapeRotationDegree, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
this->addSubObject(ls3_);
ls4_.reset(new Plane(glm::vec3(3 * landscapeRealSize * cos(glm::radians(30.0f)), -50.0f + 3 * landscapeRealSize * sin(glm::radians(30.0f)), 0.0f),landscapeTexturePath, glm::vec3(0.0f, 0.0f, 1.0f),
30.0f, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
ls4_.reset(new Plane(glm::vec3(3 * landscapeX, -50.0f + 3 * landscapeY, 0.0f), landscapeRotationAxis,
landscapeRotationDegree, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
this->addSubObject(ls4_);
ls5_.reset(new Plane(glm::vec3(4 * landscapeRealSize * cos(glm::radians(30.0f)), -50.0f + 4 * landscapeRealSize * sin(glm::radians(30.0f)), 0.0f),landscapeTexturePath, glm::vec3(0.0f, 0.0f, 1.0f),
30.0f, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
ls5_.reset(new Plane(glm::vec3(4 * landscapeX, -50.0f + 4 * landscapeY, 0.0f), landscapeRotationAxis,
landscapeRotationDegree, glm::vec3(landscapeScaling, landscapeScaling, landscapeScaling)));
this->addSubObject(ls5_);
// Skybox
float skyboxSize = 10000.0f;
std::string skyboxTexturePathPrefix = "C:/dev/uni/DTE-3609_VR_graphics_animation/start_code/resources/textures/skybox_";
sbw_.reset(new Plane(glm::vec3(-skyboxSize / 2, 0, 0.0f), skyboxTexturePathPrefix + "west.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
90.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbw_);
sbn_.reset(new Plane(glm::vec3(0.0f, 0.0f, -skyboxSize / 2), skyboxTexturePathPrefix + "north.bmp", glm::vec3(0.0f, 0.0f, 0.0f),
0.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbn_);
sbe_.reset(new Plane(glm::vec3(skyboxSize / 2, 0.0f, 0.0f), skyboxTexturePathPrefix + "east.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
270.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbe_);
sbs_.reset(new Plane(glm::vec3(0.0f, 0.0f, skyboxSize / 2),skyboxTexturePathPrefix + "south.bmp", glm::vec3(0.0f, 1.0f, 0.0f),
180.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbs_);
sbu_.reset(new Plane(glm::vec3(0.0f, skyboxSize / 2, 0.0f), skyboxTexturePathPrefix + "up.bmp", glm::vec3(1.0f, 0.0f, 0.0f),
90.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, true));
this->addSubObject(sbu_);
sbd_.reset(new Plane(glm::vec3(0.0f, -skyboxSize / 2, 0.0f), skyboxTexturePathPrefix + "down.bmp", glm::vec3(0.0f, 0.0f, 0.0f),
0.0f, glm::vec3(skyboxSize / 200, skyboxSize / 200, skyboxSize / 200), true, false));
this->addSubObject(sbd_);
sb_.reset(new Skybox());
this->addSubObject(sb_);
// Character
character_.reset(new Character());
......
......@@ -2,10 +2,10 @@
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/type_ptr.hpp"
#include "../include/Projection.h"
Plane::Plane(glm::vec3 trans, std::string texturePath, glm::vec3 rotationAxis, float rotationAngle, glm::vec3 scale, bool isFixed, bool isTilted)
: texture(Texture(texturePath)), fixed(isFixed), scaling(scale[0])
Plane::Plane(glm::vec3 trans, glm::vec3 rotationAxis, float rotationAngle, glm::vec3 scale)
: scaling(scale[0])
{
auto translation = glm::translate(glm::mat4(1.0f), trans);
......@@ -14,10 +14,6 @@ Plane::Plane(glm::vec3 trans, std::string texturePath, glm::vec3 rotationAxis, f
if (rotationAngle != 0.0f) {
rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(rotationAngle), rotationAxis);
}
if (isTilted) {
// rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(-30.0f), glm::vec3(0.0f, 0.0f, 1.0f));
rotation *= glm::rotate(glm::mat4(1.0f), glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f));
}
auto scaling = glm::scale(glm::mat4(1.0f), scale);
......@@ -68,10 +64,9 @@ void Plane::privateRender()
ibo.Bind();
texture.Bind(textureSlot);
glm::mat4 projectionMatrix = glm::perspective(glm::radians(proj::PoV), proj::aspectRatio, proj::nearClip, proj::farClip);
glm::mat4 mvp = projectionMatrix * viewMatrix_ * matrix_;
shader.SetUniformMat4f("u_MVP", mvp);
shader.SetUniformMat4f("u_ViewMatrix", viewMatrix_);
shader.SetUniformMat4f("u_ProjectionMatrix", projMatrix_);
shader.SetUniformMat4f("u_ModelMatrix", matrix_);
GLCall(glDrawElements(GL_QUADS, ibo.GetCount(), GL_UNSIGNED_INT, nullptr));
......@@ -141,9 +136,6 @@ void Plane::privateRender()
void Plane::privateUpdate()
{
if (fixed)
return;
if (matrix_[3].x < - 1.5 * 200 * scaling) {
matrix_ = glm::translate(matrix_, glm::vec3(1.5 * 200 * scaling - 2, 0.0f, 0.0f));
}
......
#include "../include/Skybox.h"
#include "../../glm-master/glm/glm.hpp"
#include "../../glm-master/glm/gtc/type_ptr.hpp"
#include "../include/Projection.h"
Skybox::Skybox()
{
auto scale = 5000.0f;
auto scaling = glm::scale(glm::mat4(1.0f), glm::vec3(scale, scale, scale));
matrix_ = scaling;
}
Skybox::~Skybox()
{
}
void Skybox::privateInit()
{
/* VERTEX BUFFER */
// Is set up in initialization of object attribute
/* LAYOUT */
// 3 floats for world position
layout.Push<float>(3);
// 2 floats for texture position
// layout.Push<float>(2);
/* VERTEX ARRAY */
vao.AddBuffer(vbo, layout);
/* INDEX BUFFER */
// Is set up in initialization of object attribute
/* SHADER */
shader.Bind();
// shader.SetUniform4f("u_Color", 0.0f, 0.0f, 1.0f, 1.0f);
/* TEXTURE */
texture.BindCubemap(textureSlot);
shader.SetUniform1i("u_Texture", textureSlot);
/* UNBINDING */
texture.UnbindCubemap();
vao.Unbind();
vbo.Unbind();
ibo.Unbind();
shader.Unbind();
}
void Skybox::privateRender()
{
shader.Bind();
vao.Bind();
ibo.Bind();
texture.BindCubemap(textureSlot);
shader.SetUniformMat4f("u_ViewMatrix", viewMatrix_);
shader.SetUniformMat4f("u_ProjectionMatrix", projMatrix_);
shader.SetUniformMat4f("u_ModelMatrix", matrix_);
GLCall(glDrawElements(GL_TRIANGLES, ibo.GetCount(), GL_UNSIGNED_INT, nullptr));
texture.UnbindCubemap();
ibo.Unbind();
vao.Unbind();
shader.Unbind();
// // Draw filled polygons
// glColor3f(0.0f, 1.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 0, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(0.0f, 0.0f, 1.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 4, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 1.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 8, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(0.2f, 0.2f, 0.2f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 12, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// // Drawing wireframe of polygons
// glEnable(GL_POLYGON_OFFSET_LINE);
// glPolygonOffset(-1.0, -1.0);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 0, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 4, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 8, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glColor3f(1.0f, 0.0f, 0.0f);
// glEnableClientState(GL_VERTEX_ARRAY);
// glVertexPointer(3, GL_FLOAT, 0, vertexArray_.data());
// glDrawArrays(GL_QUADS, 12, 4);
// glDisableClientState(GL_VERTEX_ARRAY);
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// glDisable(GL_POLYGON_OFFSET_LINE);
}
void Skybox::privateUpdate()
{
}
......@@ -29,6 +29,40 @@ Texture::Texture(const std::string& filepath)
}
}
Texture::Texture(const std::vector<std::string> faces)
: m_LocalBuffer(nullptr),
m_Width(0), m_Height(0), m_BPP(0)
{
stbi_set_flip_vertically_on_load(0);
GLCall(glGenTextures(1, &m_RendererID));
GLCall(glBindTexture(GL_TEXTURE_CUBE_MAP, m_RendererID));
for (unsigned int i = 0; i < faces.size(); i++) {
m_LocalBuffer = stbi_load(faces[i].c_str(), &m_Width, &m_Height, &m_BPP, 4);
if (!m_LocalBuffer)
{
std::cout << "FAILED TO LOAD TEXTURE FROM " << faces[i] <<"\nFAILURE REASON: "<< stbi_failure_reason() << std::endl;
}
else {
GLCall(glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_LocalBuffer));
}
}
GLCall(glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR));