From: Peter Schaefer Date: Wed, 13 Apr 2016 14:39:16 +0000 (+0200) Subject: Plane X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=4b8f37fab6c33e99d454e50262df9fe32404d888;p=cgue_weave.git Plane BasicShader --- diff --git a/Weave/Graphix/Model/BBox.cpp b/Weave/Graphix/Model/BBox.cpp index fb26910..cd5ef1e 100644 --- a/Weave/Graphix/Model/BBox.cpp +++ b/Weave/Graphix/Model/BBox.cpp @@ -4,6 +4,7 @@ #include "../../GLM.h" + BBox::BBox() { numvertices = 8; diff --git a/Weave/Graphix/Model/Plane.cpp b/Weave/Graphix/Model/Plane.cpp new file mode 100644 index 0000000..454a48d --- /dev/null +++ b/Weave/Graphix/Model/Plane.cpp @@ -0,0 +1,45 @@ +#include "Plane.h" + +#include "GL\glew.h" +#include "../../GLM.h" + + +Plane::Plane() +{ + numvertices = 4; + + vertex = new float[numvertices * 3] {-1.f, -1.f, 0.f, 1.f, -1.f, 0.f, 1.f, 1.f, 0.f, -1.f, 1.f, 0.f}; + uvs = new float[numvertices * 2]{ 0.f, 0.f, 1.f, 0.f, 1.f, 1.f, 0.f, 1.f}; + + //import("skybox.dae", numvertices, numfaces, vertex, uvs, normals, index, 0); + + //bindModel(); + bt_init(); + + name = "Plane"; + +} + +Plane::~Plane() +{ + //delete bt_collision_shape; //done inside Model.cpp +} + + +void Plane::drawModel() const +{ + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glBindVertexArray(0); +} + +void Plane::bt_init(bool isConvex) +{ + if(bt_collision_shape==nullptr) + bt_collision_shape = new btBoxShape(btVector3(.5f, .5f, .5f)); +} + + +std::string Plane::type2str() const +{ + return "Plane"; +} diff --git a/Weave/Graphix/Model/Plane.h b/Weave/Graphix/Model/Plane.h new file mode 100644 index 0000000..90121fb --- /dev/null +++ b/Weave/Graphix/Model/Plane.h @@ -0,0 +1,18 @@ +#pragma once + +#include "Model.h" + +class Plane : + public Model +{ +public: + Plane(); + ~Plane(); + + void drawModel() const override; + + void bt_init(bool isConvex = true) override; + + std::string type2str() const override; +}; + diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index b17a61e..4ee0f1c 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -35,7 +35,15 @@ void SkyBox::drawModel(const mat4& _modelMat) const //glCullFace(GL_FRONT); glDepthFunc(GL_LEQUAL); //glDisable(GL_DEPTH_TEST); - Model::drawModel(_modelMat); + + useModel(_modelMat); + + GLboolean far = true; + int tmp = Shader::gBasicTexture()->getUniformLocation("uFar"); + if (tmp >= 0) + glUniform1i(tmp, far); + + Model::drawModel(); //glEnable(GL_DEPTH_TEST); //glCullFace(OldCullFaceMode); glDepthFunc(OldDepthFuncMode); diff --git a/Weave/Graphix/Shader.cpp b/Weave/Graphix/Shader.cpp index 46af2c1..0ba0ffa 100644 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@ -147,15 +147,17 @@ void Shader::init() { if(shBasic==nullptr) shBasic = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); + if (shBasicTexture == nullptr) + shBasicTexture = new Shader("basic_VS.hlsl", "basicTexture_FS.hlsl"); if(shLighting==nullptr) shLighting = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl"); if(shBlur==nullptr) - shBlur = new Shader("plane_VS.hlsl", "blur_FS.hlsl"); + shBlur = new Shader("basic_VS.hlsl", "blur_FS.hlsl"); } void Shader::cleanup() { - delete shBasic, shLighting, shBlur; + delete shBasic, shBasicTexture, shLighting, shBlur; } const Shader * Shader::gActive() @@ -168,6 +170,11 @@ const Shader * Shader::gBasic() return shBasic; } +const Shader * Shader::gBasicTexture() +{ + return shBasicTexture; +} + const Shader * Shader::gLighting() { return shLighting; @@ -180,5 +187,6 @@ const Shader * Shader::gBlur() const Shader * Shader::shActive = nullptr; const Shader * Shader::shBasic = nullptr; +const Shader * Shader::shBasicTexture = nullptr; const Shader * Shader::shLighting = nullptr; const Shader * Shader::shBlur = nullptr; diff --git a/Weave/Graphix/Shader.h b/Weave/Graphix/Shader.h index 460ee3d..2128e12 100644 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@ -22,6 +22,7 @@ public: static const Shader * gActive(); static const Shader * gBasic(); + static const Shader * gBasicTexture(); static const Shader * gLighting(); static const Shader * gBlur(); @@ -37,6 +38,7 @@ private: static const Shader * shActive; static const Shader * shBasic; + static const Shader * shBasicTexture; static const Shader * shLighting; static const Shader * shBlur; }; diff --git a/Weave/Scene/Sky.cpp b/Weave/Scene/Sky.cpp index 604aa67..5e4459a 100644 --- a/Weave/Scene/Sky.cpp +++ b/Weave/Scene/Sky.cpp @@ -2,14 +2,17 @@ #include "../Graphix/Shader.h" #include "../Graphix/Model.h" +#include "../Graphix/Texture.h" #include "../GLM.h" +#include -Sky::Sky() : SceneObject(new Shader("skybox_VS.hlsl","basicTexture_FS.hlsl"), scale(vec3(20.f)), vec4(1.f), Model::getSkyBoxModel(), "model_skybox_2D.png") + +Sky::Sky() : SceneObject(Shader::gBasicTexture(), scale(vec3(20.f)), vec4(1.f), Model::getSkyBoxModel(), "model_skybox_2D.png") { - modelMat[3][3] = 0; + modelMat[3][3] = 0.f; } diff --git a/Weave/Weave.vcxproj b/Weave/Weave.vcxproj index 53f2a93..2f71aa7 100644 --- a/Weave/Weave.vcxproj +++ b/Weave/Weave.vcxproj @@ -103,6 +103,7 @@ + @@ -133,6 +134,7 @@ + diff --git a/Weave/Weave.vcxproj.filters b/Weave/Weave.vcxproj.filters index fe9d56b..d96246b 100644 --- a/Weave/Weave.vcxproj.filters +++ b/Weave/Weave.vcxproj.filters @@ -57,37 +57,40 @@ Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + + Source Files + + Source Files @@ -140,40 +143,43 @@ Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + Header Files - + + Header Files + + Header Files diff --git a/shader/basic_VS.hlsl b/shader/basic_VS.hlsl index 55bb6c2..56a8a28 100644 --- a/shader/basic_VS.hlsl +++ b/shader/basic_VS.hlsl @@ -2,10 +2,30 @@ #version 330 core in vec3 aPosition; +in vec2 aUVs; + uniform mat4 uProjection; -uniform mat4 uModel; +uniform mat4 uModel = mat4(1.f); uniform mat4 uView; -void main(){ - gl_Position = uProjection * uView * uModel * vec4(aPosition, 1); +uniform bool uFar = false; +uniform bool uPlain = false; + +out vec2 fUVs; + +void main() +{ + vec4 position; + fUVs = aUVs; + + if(uPlain) + position = vec4(aPosition, 1.f); + else + position = uProjection * uView * uModel * vec4(aPosition, 1.f); + + if (uFar) + gl_Position = position.xyww; + else + gl_Position = position; + } diff --git a/shader/plane_VS.hlsl b/shader/plane_VS.hlsl index 8bb350d..845903c 100644 --- a/shader/plane_VS.hlsl +++ b/shader/plane_VS.hlsl @@ -7,6 +7,6 @@ out vec2 fUVs; void main() { - gl_Position = vec4(aPosition, 1.0f); - fUVs = aUVs; + fUVs = aUVs; + gl_Position = vec4(aPosition, 1.0f); } \ No newline at end of file diff --git a/shader/skybox_VS.hlsl b/shader/skybox_VS.hlsl index f30317d..5afc37f 100644 --- a/shader/skybox_VS.hlsl +++ b/shader/skybox_VS.hlsl @@ -10,7 +10,6 @@ uniform mat4 uProjection, uView, uModel=mat4(1.f); void main() { - fUVs = aUV; gl_Position = (uProjection * uView * uModel * vec4(aPosition, 1.f)).xyww; } \ No newline at end of file