Skip to content

Commit

Permalink
Sky box test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hopson97 committed Jul 10, 2017
1 parent 2ef19cb commit 0d2cc5c
Show file tree
Hide file tree
Showing 30 changed files with 335 additions and 71 deletions.
11 changes: 11 additions & 0 deletions Data/Shaders/SkyBox_Fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 330 core
out vec4 outColour;

in vec3 passTexCoords;

uniform samplerCube skybox;

void main()
{
outColour = vec4(1, 1, 0, 1);//texture(skybox, passTexCoords);
}
14 changes: 14 additions & 0 deletions Data/Shaders/SkyBox_Vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 330 core

layout (location = 0) in vec3 inVertexCoords;

out vec3 passTexCoords;

uniform mat4 projection;
uniform mat4 view;

void main()
{
passTexCoords = inVertexCoords;
gl_Position = projection * view * vec4(inVertexCoords, 1.0);
}
14 changes: 14 additions & 0 deletions Data/Textures/Skybox/Test/README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
UPDATED THE 28TH, REMOVED A FUNKY PLANET

INTERSTELLAR
high res 1024^2 environment map
ships as TGA.


By Jockum Skoglund aka hipshot
[email protected]
www.zfight.com
Stockholm, 2005 08 25


Modify however you like, just cred me for my work, maybe link to my page.
Binary file added Data/Textures/Skybox/Test/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Textures/Skybox/Test/bottom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Textures/Skybox/Test/front.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Textures/Skybox/Test/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Textures/Skybox/Test/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Data/Textures/Skybox/Test/top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void Application::runMainGameLoop()
auto currentTime = timer.getElapsedTime();
auto elapsed = currentTime - lastTime;
lastTime = currentTime;
tickLag = elapsed;
tickLag += elapsed;

handleEvents();
if (m_states.empty()) break;
Expand Down
11 changes: 11 additions & 0 deletions Source/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,14 @@ const Matrix4& Camera::getProjectionViewMatrix() const noexcept
{
return m_projectionViewMatrix;
}

const Matrix4& Camera::getViewMatrix() const noexcept
{
return m_viewMatrix;
}

const Matrix4& Camera::getProjMatrix() const noexcept
{
return m_projectionMatrix;
}

4 changes: 3 additions & 1 deletion Source/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Camera : public Entity

const Frustum& getFrustum() const noexcept;

const Matrix4& getProjectionViewMatrix() const noexcept;
const Matrix4& getProjectionViewMatrix () const noexcept;
const Matrix4& getViewMatrix () const noexcept;
const Matrix4& getProjMatrix () const noexcept;

private:
const Entity* m_pEntity = nullptr;
Expand Down
1 change: 1 addition & 0 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace
MessageBox(nullptr, message.c_str(), "Error", MB_OK);
std::cerr << message << std::endl;
#elif __linux__ || __APPLE__
///@TODO Test
const std::string command = "zenity --error --text \"" + message + "\"";
system(command.c_str());
#else
Expand Down
11 changes: 11 additions & 0 deletions Source/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ Model::Model(const std::vector<GLfloat>& vertexPositions,
addEBO(indices);
}

Model::Model(const std::vector<GLfloat>& vertexPositions,
const std::vector<GLuint>& indices)
: m_indicesCount (indices.size())
{
glGenVertexArrays(1, &m_vao);
bind();

addVBO(3, vertexPositions);
addEBO(indices);
}

Model::Model(Model&& other)
: m_vao (other.m_vao)
, m_vboCount (other.m_vboCount)
Expand Down
3 changes: 3 additions & 0 deletions Source/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class Model
const std::vector<GLfloat>& textureCoordinates,
const std::vector<GLuint>& indices);

Model(const std::vector<GLfloat>& vertexPositions,
const std::vector<GLuint>& indices);

~Model();
Model(const Model& other) = delete;
Model& operator =(const Model& other) = delete;
Expand Down
50 changes: 25 additions & 25 deletions Source/ModelCoords.cpp
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#include "ModelCoords.h"

std::vector<GLfloat> getCubeVerticies(float scale)
std::vector<GLfloat> getCubeVerticies(float posScale, float negScale)
{
return
{
//Back
1 * scale, 0, 0,
0, 0, 0,
0, 1 * scale, 0,
1 * scale, 1 * scale, 0,
1 * posScale, -1 * negScale, -1 * negScale,
-1 * negScale, -1 * negScale, -1 * negScale,
-1 * negScale, 1 * posScale, -1 * negScale,
1 * posScale, 1 * posScale, -1 * negScale,

//Right-Side
1 * scale, 0, 1 * scale,
1 * scale, 0, 0,
1 * scale, 1 * scale, 0,
1 * scale, 1 * scale, 1 * scale,
1 * posScale, -1 * negScale, 1 * posScale,
1 * posScale, -1 * negScale, -1 * negScale,
1 * posScale, 1 * posScale, -1 * negScale,
1 * posScale, 1 * posScale, 1 * posScale,

//Front
0, 0, 1 * scale,
1 * scale, 0, 1 * scale,
1 * scale, 1 * scale, 1 * scale,
0, 1 * scale, 1 * scale,
-1 * negScale, -1 * negScale, 1 * posScale,
1 * posScale, -1 * negScale, 1 * posScale,
1 * posScale, 1 * posScale, 1 * posScale,
-1 * negScale, 1 * posScale, 1 * posScale,

//Left
0, 0, 0,
0, 0, 1 * scale,
0, 1 * scale, 1 * scale,
0, 1 * scale, 0,
-1 * negScale, -1 * negScale, -1 * negScale,
-1 * negScale, -1 * negScale, 1 * posScale,
-1 * negScale, 1 * posScale, 1 * posScale,
-1 * negScale, 1 * posScale, -1 * negScale,

//Top
0, 1 * scale, 1 * scale,
1 * scale, 1 * scale, 1 * scale,
1 * scale, 1 * scale, 0,
0, 1 * scale, 0,
-1 * negScale, 1 * posScale, 1 * posScale,
1 * posScale, 1 * posScale, 1 * posScale,
1 * posScale, 1 * posScale, -1 * negScale,
-1 * negScale, 1 * posScale, -1 * negScale,

//Bottom
0, 0, 0,
1 * scale, 0, 0,
1 * scale, 0, 1 * scale,
0, 0, 1 * scale
-1 * negScale, -1 * negScale, -1 * negScale,
1 * posScale, -1 * negScale, -1 * negScale,
1 * posScale, -1 * negScale, 1 * posScale,
-1 * negScale, -1 * negScale, 1 * posScale
};
}

Expand Down
2 changes: 1 addition & 1 deletion Source/ModelCoords.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct ModelData
std::vector<GLuint> indices;
};

std::vector<GLfloat> getCubeVerticies (float scale = 1.0f);
std::vector<GLfloat> getCubeVerticies (float posScale = 1.0f, float negScale = 0.0f);
std::vector<GLuint> getCubeIndices ();

#endif // MODEL_COORDS_H_INCLUDED
9 changes: 7 additions & 2 deletions Source/Renderer/RMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ namespace Renderer

void Master::update(const Camera& camera)
{
///@TODO This is starting to feel a bit bad
///Another way to do this?
Block::Database::get().getTextureAtlas().bind();

glEnable(GL_DEPTH_TEST);
m_simpleRenderer.update(camera);
m_skyBoxRenderer.update(camera);

glDisable(GL_DEPTH_TEST);
m_sfmlRenderer.update ();
Expand All @@ -38,4 +37,10 @@ namespace Renderer
{
m_simpleRenderer.draw(cube);
}

void Master::draw(const Texture::CubeTexture& tex)
{
m_skyBoxRenderer.draw(tex);
}

}
4 changes: 4 additions & 0 deletions Source/Renderer/RMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "RSFML.h"
#include "RSimple.h"
#include "RSkyBox.h"

struct Camera;

Expand All @@ -19,9 +20,12 @@ namespace Renderer
void draw(const sf::Drawable& drawable);
void draw(const Cube& cube);

void draw(const Texture::CubeTexture& tex);

private:
RSFML m_sfmlRenderer;
RSimple m_simpleRenderer;
SkyBox m_skyBoxRenderer;
};
}

Expand Down
4 changes: 4 additions & 0 deletions Source/Renderer/RSFML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ namespace Renderer
glDisable(GL_DEPTH_TEST);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

glBindTexture(GL_TEXTURE_2D, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);

glUseProgram(0);


Display::get().getRaw().pushGLStates();
Display::get().getRaw().resetGLStates();

Expand Down
115 changes: 115 additions & 0 deletions Source/Renderer/RSkyBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "RSkyBox.h"

#include "../Camera.h"
#include "../Texture/CubeTexture.h"

#include "../ModelCoords.h"

#include "../Maths/Matrix.h"

#include <iostream>

float skyboxVertices[] = {
// positions
-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,

-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,

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,

-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,

-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,

-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
};

GLuint vbo;

namespace Renderer
{
SkyBox::SkyBox()
: m_shader("SkyBox", "SkyBox")
//, m_cube (getCubeVerticies(10.0f, 10.0f), getCubeIndices())
{
glBindVertexArray(0);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER,
sizeof(skyboxVertices),
skyboxVertices,
GL_STATIC_DRAW);

glVertexAttribPointer(0,
3,
GL_FLOAT,
GL_FALSE,
0,
(GLvoid*) 0);

}

void SkyBox::draw(const Texture::CubeTexture& cubeTex)
{
m_pCubeMap = &cubeTex;
}

void SkyBox::update(const Camera& camera)
{
if(!m_pCubeMap) return;

glDepthMask(GL_FALSE);
m_shader .bind(); //shader
//m_cube .bind(); //VAO
m_pCubeMap ->bind(); //texture

glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

const auto& view = camera.getViewMatrix();
const auto& proj = camera.getProjMatrix();

auto sView = Matrix4(glm::mat3(view));

m_shader.setProjViewMatrix (proj * sView);

glDrawArrays(GL_TRIANGLES, 0, 36);

//glDisable(GL_CULL_FACE);
//glDrawElements(GL_TRIANGLES, m_cube.getIndicesCount(), GL_UNSIGNED_INT, nullptr);

glDepthMask(GL_TRUE);
m_pCubeMap = nullptr;
}
}
Loading

0 comments on commit 0d2cc5c

Please sign in to comment.