This commit is contained in:
Adam
2014-03-14 01:50:37 +01:00
parent 9a2bdf8c11
commit 72c06231ad
27 changed files with 1368 additions and 7 deletions
-1
View File
@@ -16,7 +16,6 @@ public:
glm::vec3 Forward();
glm::vec3 Right();
glm::quat Orientation();
float AspectRatio() const { return m_AspectRatio; }
void AspectRatio(float val);
+47
View File
@@ -0,0 +1,47 @@
#include "CubemapTexture.h"
CubemapTexture::CubemapTexture(char* posXFile, char* negXFile, char* posYFile, char* negYFile, char* posZFile, char* negZFile)
{
m_TextureFiles[0] = posXFile;
m_TextureFiles[1] = negXFile;
m_TextureFiles[2] = posYFile;
m_TextureFiles[3] = negYFile;
m_TextureFiles[4] = posZFile;
m_TextureFiles[5] = negZFile;
Load();
}
CubemapTexture::~CubemapTexture()
{
//glDeleteTextures(1, &m_Texture);
}
void CubemapTexture::Load()
{
m_Texture = SOIL_load_OGL_cubemap(
m_TextureFiles[0],
m_TextureFiles[1],
m_TextureFiles[2],
m_TextureFiles[3],
m_TextureFiles[4],
m_TextureFiles[5],
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
0);
if (m_Texture == 0)
LOG_ERROR("SOIL cubemap loading error: %s", SOIL_last_result());
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
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);
}
void CubemapTexture::Bind(GLenum textureUnit)
{
glActiveTexture(textureUnit);
glBindTexture(GL_TEXTURE_CUBE_MAP, m_Texture);
}
+31
View File
@@ -0,0 +1,31 @@
#ifndef CubemapTexture_h__
#define CubemapTexture_h__
#include "OpenGL.h"
#include "glerror.h"
#include <SOIL.h>
#include "logging.h"
class CubemapTexture
{
public:
CubemapTexture() { }
CubemapTexture(
char* posXFile,
char* negXFile,
char* posYFile,
char* negYFile,
char* posZFile,
char* negZFile);
~CubemapTexture();
void Load();
void Bind(GLenum textureSlot);
private:
char* m_TextureFiles[6];
GLuint m_Texture;
};
#endif // CubemapTexture_h__
+6
View File
@@ -98,6 +98,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Camera.cpp" />
<ClCompile Include="CubemapTexture.cpp" />
<ClCompile Include="Engine.h" />
<ClCompile Include="Frame.cpp" />
<ClCompile Include="GameFrame.cpp" />
@@ -109,6 +110,7 @@
<ClCompile Include="OBJ.cpp" />
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="ShaderProgram.cpp" />
<ClCompile Include="Skybox.cpp" />
<ClCompile Include="Systems\CollisionSystem.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="TextFrame.cpp" />
@@ -125,6 +127,7 @@
<ClInclude Include="Color.h" />
<ClInclude Include="Component.h" />
<ClInclude Include="Components\Camera.h" />
<ClInclude Include="CubemapTexture.h" />
<ClInclude Include="Factory.h" />
<ClInclude Include="Components\Bounds.h" />
<ClInclude Include="Components\Collision.h" />
@@ -153,6 +156,7 @@
<ClInclude Include="OpenGL.h" />
<ClInclude Include="Renderer.h" />
<ClInclude Include="ShaderProgram.h" />
<ClInclude Include="Skybox.h" />
<ClInclude Include="Systems\InputSystem.h" />
<ClInclude Include="System.h" />
<ClInclude Include="Systems\CollisionSystem.h" />
@@ -171,6 +175,8 @@
<None Include="Shaders\Fragment.glsl" />
<None Include="Shaders\Normals.frag.glsl" />
<None Include="Shaders\Normals.geo.glsl" />
<None Include="Shaders\Skybox.frag.glsl" />
<None Include="Shaders\Skybox.vert.glsl" />
<None Include="Shaders\VisualizeDepth.frag.glsl" />
<None Include="Shaders\VisualizeDepth.vert.glsl" />
<None Include="Shaders\ShadowMap.frag.glsl" />
@@ -47,6 +47,8 @@
<ClCompile Include="OBJ.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="GameWorld.cpp" />
<ClCompile Include="Skybox.cpp" />
<ClCompile Include="CubemapTexture.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Component.h" />
@@ -148,6 +150,8 @@
<ClInclude Include="Camera.h" />
<ClInclude Include="OBJ.h" />
<ClInclude Include="OpenGL.h" />
<ClInclude Include="Skybox.h" />
<ClInclude Include="CubemapTexture.h" />
</ItemGroup>
<ItemGroup>
<None Include="Shaders\Fragment.glsl">
@@ -180,6 +184,12 @@
<None Include="Shaders\AABB.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\Skybox.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="Shaders\Skybox.vert.glsl">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="Systems">
+2 -2
View File
@@ -108,12 +108,12 @@ void GameWorld::Initialize()
bounds->VolumeVector = glm::vec3(4.f, 0.7f, 1);
soundEmitter = AddComponent<Components::SoundEmitter>(m_Player, "SoundEmitter");
soundEmitter->Loop = true;
//soundEmitter->MaxDistance = FLT_MAX;
//soundEmitter->MaxDistance = 10;
soundEmitter->ReferenceDistance = 10;
soundEmitter->Gain = 1;
soundEmitter->Pitch = 1;
soundEmitter->Path = "Sounds/hallelujah.wav";
GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter);
//GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(soundEmitter);
File diff suppressed because it is too large Load Diff
+50 -2
View File
@@ -99,6 +99,13 @@ void Renderer::LoadContent()
m_ShaderProgramDebugAABB.Compile();
m_ShaderProgramDebugAABB.Link();
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Skybox.vert.glsl")));
m_ShaderProgramSkybox.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Skybox.frag.glsl")));
m_ShaderProgramSkybox.Compile();
m_ShaderProgramSkybox.Link();
m_Skybox = std::make_shared<Skybox>(CubemapTexture("Textures/right.jpg", "Textures/left.jpg", "Textures/top.jpg", "Textures/bottom.jpg", "Textures/front.jpg", "Textures/back.jpg"));
m_DebugAABB = CreateAABB();
m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes);
@@ -133,6 +140,7 @@ void Renderer::Draw(double dt)
{
glDisable(GL_BLEND);
DrawSkybox();
DrawShadowMap();
DrawScene();
@@ -167,13 +175,26 @@ void Renderer::Draw(double dt)
glfwSwapBuffers(m_Window);
}
void Renderer::DrawScene()
void Renderer::DrawSkybox()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
m_ShaderProgramSkybox.Bind();
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * glm::toMat4(m_Camera->Orientation());
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramSkybox.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(cameraMatrix));
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
m_Skybox->Draw();
}
void Renderer::DrawScene()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_DEPTH_BUFFER_BIT);
//glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
@@ -461,6 +482,33 @@ GLuint Renderer::CreateAABB()
return vao;
}
GLuint Renderer::CreateSkybox()
{
glm::vec3 skyBoxVertices[] =
{
glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f),
glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, 1.0f),
glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, -1.0f),
glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, 1.0f),
glm::vec3( 1.0f, -1.0f, 1.0f), glm::vec3(-1.0f, -1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3(-1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, 1.0f, 1.0f), glm::vec3( 1.0f, -1.0f, 1.0f),
glm::vec3(-1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, -1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3( 1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, 1.0f, -1.0f), glm::vec3(-1.0f, -1.0f, -1.0f)
};
GLuint vbo, vao;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(skyBoxVertices), skyBoxVertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
return vao;
}
void Renderer::ClearStuff()
{
AABBsToRender.clear();
+8
View File
@@ -20,6 +20,7 @@
#include "ShaderProgram.h"
#include "Model.h"
#include "Components/PointLight.h"
#include "Skybox.h"
class Renderer
{
@@ -71,6 +72,9 @@ public:
void DrawWireframe(bool val) { m_DrawWireframe = val; }
bool DrawBounds() const { return m_DrawBounds; }
void DrawBounds(bool val) { m_DrawBounds = val; }
void DrawSkybox();
private:
GLFWwindow* m_Window;
@@ -81,6 +85,8 @@ private:
bool m_DrawWireframe;
bool m_DrawBounds;
std::shared_ptr<Skybox> m_Skybox;
int m_ShadowMapRes;
glm::vec3 m_SunPosition;
glm::vec3 m_SunTarget;
@@ -98,6 +104,7 @@ private:
ShaderProgram m_ShaderProgramShadows;
ShaderProgram m_ShaderProgramShadowsDrawDepth;
ShaderProgram m_ShaderProgramDebugAABB;
ShaderProgram m_ShaderProgramSkybox;
void ClearStuff();
void DrawScene();
@@ -107,6 +114,7 @@ private:
GLuint CreateQuad();
void DrawDebugShadowMap();
GLuint CreateAABB();
GLuint CreateSkybox(void);
};
+15
View File
@@ -0,0 +1,15 @@
#version 430
uniform samplerCube CubemapTexture;
in VertexData {
vec3 TextureCoord;
} Input;
out vec4 FragColor;
void main()
{
FragColor = texture(CubemapTexture, Input.TextureCoord);
//FragColor = vec4(1.0, 1.0, 1.0, 0.0);
}
+15
View File
@@ -0,0 +1,15 @@
#version 430
uniform mat4 MVP;
layout(location = 0) in vec3 Position;
out VertexData {
vec3 TextureCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.TextureCoord = Position;
}
+79
View File
@@ -0,0 +1,79 @@
#include "Skybox.h"
Skybox::Skybox(CubemapTexture cubemap)
{
m_Cubemap = cubemap;
float cubeVertices[] = {
-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,
};
//std::copy(cubeVertices, cubeVertices + (3*8 - 1), m_CubeVertices);
unsigned int cubeIndices[] = {
// Back
0, 2, 3,
0, 1, 2,
// Right
1, 6, 2,
1, 5, 6,
// Front
5, 7, 6,
5, 4, 7,
// Left
4, 3, 7,
4, 0, 3,
// Top
3, 6, 7,
3, 2, 6,
// Bottom
4, 1, 0,
4, 5, 1,
};
//std::copy(cubeIndices, cubeIndices + (3*12 - 1), m_CubeIndices);
GLuint vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 3 * 8 * sizeof(float), cubeVertices, GL_STATIC_DRAW);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * 12 * sizeof(int), cubeIndices, GL_STATIC_DRAW);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
GLERROR("");
}
Skybox::~Skybox()
{
}
void Skybox::Draw()
{
m_Cubemap.Bind(GL_TEXTURE0);
glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDepthMask(GL_FALSE);
glDrawElements(GL_TRIANGLES, 3 * 12, GL_UNSIGNED_INT, 0);
glDepthMask(GL_TRUE);
}
+29
View File
@@ -0,0 +1,29 @@
#ifndef Skybox_h__
#define Skybox_h__
#include <algorithm>
#include "OpenGL.h"
#include "logging.h"
#include "glerror.h"
#include "CubemapTexture.h"
class Skybox
{
public:
Skybox(CubemapTexture cubemap);
~Skybox();
void Draw();
private:
CubemapTexture m_Cubemap;
GLuint ibo;
GLuint vao;
float m_CubeVertices[3 * 8];
int m_CubeIndices[1];
};
#endif // Skybox_h__
@@ -32,7 +32,7 @@ void Systems::LevelGenerationSystem::SpawnObstacle()
sound->Loop = true;
sound->Gain = 1.f;
sound->ReferenceDistance = 15.f;
sound->ReferenceDistance = 4.f;
m_World->GetSystem<Systems::SoundSystem>("SoundSystem")->PlaySound(sound, "Sounds/hum.wav");
if(typeRandom >= 0 && typeRandom < 2) // Mountain stuff :D
+1 -1
View File
@@ -198,7 +198,7 @@ ALuint Systems::SoundSystem::CreateSource()
ALuint source;
alGenSources((ALuint)1, &source);
alDopplerFactor(2.f); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect
alDopplerFactor(1); // Numbers greater than 1 will increase Doppler effect, numbers lower than 1 will decrease the Doppler effect
alDopplerVelocity(350.f); // Defines the velocity of the sound
return source;
Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 489 KiB