#include "BBox.h"\r
#include "SkyBox.h"\r
#include "IMetaMesh.h"\r
+#include "Plane.h"\r
\r
#include "../../Events.h"\r
\r
return BoundingBox;\r
}\r
\r
+Model* Model::getPlaneModel()\r
+{\r
+ if (PlaneModel == nullptr)\r
+ {\r
+ PlaneModel = new Plane();\r
+ PlaneModel->bindModel();\r
+ PlaneModel->bindShader(Shader::gBasicTexture());\r
+ }\r
+ return PlaneModel;\r
+}\r
+\r
Model* Model::getSkyBoxModel()\r
{\r
if (SkyBoxModel == nullptr)\r
\r
\r
Model* Model::BoundingBox = nullptr;\r
+Model* Model::PlaneModel = nullptr;\r
Model* Model::SkyBoxModel = nullptr;\r
std::unordered_map<string, Model*> Model::IMetaModel;\r
std::unordered_map<string, uint> Model::IMetaModel_count;\r
virtual void drawBBox(const mat4& modelMat, const vec4& color = vec4(0.9f, 0.f, 0.f, 1.f)) const;\r
\r
static Model* getBBoxModel();\r
+ static Model* getPlaneModel();\r
static Model* getSkyBoxModel();\r
static Model* newIMetaModel(const std::string& modelpath,bool isConvex=true);\r
\r
\r
static Model* BoundingBox;\r
static Model* SkyBoxModel;\r
+ static Model* PlaneModel;\r
static std::unordered_map<std::string, Model*> IMetaModel;\r
static std::unordered_map<std::string, uint> IMetaModel_count;\r
\r
Plane();
~Plane();
- void drawModel() const override;
void bt_init(bool isConvex = true) override;
std::string type2str() const override;
+
+protected:
+ void drawModel() const override;
};
glAttachShader(programHandle, _shader1);
glAttachShader(programHandle, _shader2);
- glBindFragDataLocation(programHandle, 0, "fragColor");
+ //glBindFragDataLocation(programHandle, 0, "fragColor");
glLinkProgram(programHandle);
#include "Textures/Texture.h"
//#include "Textures\tImage.h"
-#include "Textures\tBuffer.h"
+#include "Textures\fBufferObject.h"
+#include "Textures\rBufferObject.h"
\ No newline at end of file
--- /dev/null
+#include "BufferObject.h"
+
+#include <GL\glew.h>
+
+
+BufferObject::BufferObject()
+{
+}
+
+
+BufferObject::~BufferObject()
+{
+}
+
+BufferObject::operator unsigned int() const
+{
+ return handle;
+}
\ No newline at end of file
--- /dev/null
+#pragma once
+class BufferObject
+{
+public:
+// BufferObject() {};
+// virtual ~BufferObject() = 0;
+
+ virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) = 0;
+ virtual void unbindBuffer() = 0;
+ virtual void useBuffer() const = 0;
+ virtual void clearBuffer() const = 0;
+
+ virtual void updateSize(unsigned int _width, unsigned int _height) = 0;
+
+ virtual operator unsigned int() const
+ {
+ return handle;
+ }
+
+ virtual unsigned int getTarget() const
+ {
+ return buffer_target;
+ }
+
+protected:
+ unsigned int handle;
+ unsigned int buffer_target;
+};
+
return handle;
}
-void Texture::bindTexture()
+void Texture::bindTexture(unsigned int _width, unsigned int _height)
{
+ if (_width != 0 && _height != 0)
+ {
+ width = _width;
+ height = _height;
+ }
+
glBindTexture(texture_target, handle);
glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glGenTextures(1, &handle);
}
-void Texture::useTexture() const
+void Texture::useTexture(unsigned int _unit) const
{
/* bind Texture*/
- int unit = 0;
- glActiveTexture(GL_TEXTURE0 + unit);
+ glActiveTexture(GL_TEXTURE0 + _unit);
glBindTexture(texture_target, handle);
}
void Texture::updateSize(unsigned int _width, unsigned int _height)
{
- width = _width;
- height = _height;
+ if (_width == 0 || _height == 0)
+ return;
glBindTexture(texture_target, handle);
glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
Texture();
~Texture();
- virtual void bindTexture();
+ virtual void bindTexture(unsigned int width = 0, unsigned int height = 0);
virtual void unbindTexture();
- virtual void useTexture() const;
+ virtual void useTexture(unsigned int i=0) const;
- virtual void updateSize(unsigned int width, unsigned int height);
+ virtual void updateSize(unsigned int width = 0, unsigned int height = 0);
virtual operator unsigned int() const;
typedef struct texStruct
{
unsigned int count=0;
- tImage* ptr=nullptr;
+ tImage* ptr=NULL;
} texHandle;
static std::unordered_map<std::string, texHandle> texture_Map;
--- /dev/null
+#include "fBufferObject.h"
+
+#include <GL\glew.h>
+#include "../Shader.h"
+#include "../../Message.h"
+
+#include "Texture.h"
+#include "rBufferObject.h"
+
+
+fBufferObject::fBufferObject(unsigned int _dim, bool _rbo)
+ : dim(_dim)
+{
+ buffer_target = GL_FRAMEBUFFER;
+
+ /*gen Buffer*/
+ glGenFramebuffers(1, &handle);
+
+
+ /*gen Texture*/
+ textures = new Texture[_dim];
+
+ if (_rbo)
+ rBO = new rBufferObject;
+}
+
+
+fBufferObject::~fBufferObject()
+{
+ delete textures;
+
+ if (rBO != nullptr)
+ delete rBO;
+
+ glDeleteFramebuffers(1, &handle);
+}
+
+unsigned int fBufferObject::getDim() const
+{
+ return dim;
+}
+
+Texture* fBufferObject::getTexture(unsigned int i) const
+{
+ return &textures[i];
+}
+
+void fBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
+{
+
+ glBindFramebuffer(buffer_target, handle);
+
+ /*Bind Texture Buffers*/
+ unsigned int* attachments = new unsigned int[dim];
+ for (unsigned int i = 0; i < dim; i++)
+ {
+ textures[i].bindTexture(_width, _height);
+ glFramebufferTexture2D(buffer_target, GL_COLOR_ATTACHMENT0 + i, textures[i].getTTarget(), textures[i], 0);
+ attachments[i] = GL_COLOR_ATTACHMENT0 + i;
+ }
+
+ /*Bind Render Buffers*/
+ if (rBO != nullptr)
+ {
+ rBO->bindBuffer(_width, _height);
+ glFramebufferRenderbuffer(buffer_target, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, *rBO);
+ }
+
+
+ //glDrawBuffers(dim, attachments);
+ if (glCheckFramebufferStatus(buffer_target) != GL_FRAMEBUFFER_COMPLETE)
+ Message::error("fBufferObject: Framebuffer not complete!");
+
+ delete attachments;
+}
+
+void fBufferObject::unbindBuffer()
+{
+ for (unsigned int i = 0; i < dim; i++)
+ {
+ textures[i].unbindTexture();
+ }
+
+ if (rBO != nullptr)
+ rBO->unbindBuffer();
+
+ glDeleteFramebuffers(1, &handle);
+ glGenFramebuffers(1, &handle);
+
+}
+
+void fBufferObject::useBuffer() const
+{
+ glBindFramebuffer(buffer_target, handle);
+
+}
+
+void fBufferObject::clearBuffer() const
+{
+ glBindFramebuffer(buffer_target, 0);
+}
+
+void fBufferObject::updateSize(unsigned int _width, unsigned int _height)
+{
+
+ for (unsigned int i = 0; i < dim; i++)
+ {
+ textures[i].updateSize(_width, _height);
+
+ }
+
+ if (rBO != nullptr)
+ rBO->updateSize(_width, _height);
+}
--- /dev/null
+#pragma once
+
+#include "BufferObject.h"
+
+class Texture;
+class rBufferObject;
+
+class fBufferObject
+ : public BufferObject
+{
+public:
+ fBufferObject(unsigned int dim=1, bool rbo = true);
+ virtual ~fBufferObject();
+
+ virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) override;
+ virtual void unbindBuffer() override;
+
+ virtual void useBuffer() const override;
+
+ virtual void clearBuffer() const override;
+
+ void updateSize(unsigned int _width, unsigned int _height);
+
+ unsigned int getDim() const;
+ Texture* getTexture(unsigned int i = 0) const;
+
+protected:
+ unsigned int dim;
+ Texture* textures = nullptr;
+
+ rBufferObject* rBO = nullptr;
+
+};
+
--- /dev/null
+#include "rBufferObject.h"
+
+#include <GL\glew.h>
+#include "../Shader.h"
+#include "../../Message.h"
+
+
+rBufferObject::rBufferObject()
+{
+ buffer_target = GL_RENDERBUFFER;
+
+ /*gen Buffer*/
+ glGenRenderbuffers(1, &handle);
+}
+
+
+rBufferObject::~rBufferObject()
+{
+ glDeleteRenderbuffers(1, &handle);
+}
+
+void rBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
+{
+ if (_width != 0 && _height != 0)
+ {
+ width = _width;
+ height = _height;
+ }
+ glBindRenderbuffer(buffer_target, handle);
+ glRenderbufferStorage(buffer_target, GL_DEPTH_COMPONENT, width, height);
+}
+
+void rBufferObject::unbindBuffer()
+{
+ glDeleteRenderbuffers(1, &handle);
+ glGenRenderbuffers(1, &handle);
+}
+
+void rBufferObject::useBuffer() const
+{
+ glBindRenderbuffer(buffer_target, handle);
+
+}
+
+void rBufferObject::clearBuffer() const
+{
+ glBindRenderbuffer(buffer_target, 0);
+}
+
+void rBufferObject::updateSize(unsigned int _width, unsigned int _height)
+{
+ bindBuffer(_width, _height);
+}
--- /dev/null
+#pragma once
+
+#include "BufferObject.h"
+
+class rBufferObject
+ : public BufferObject
+{
+public:
+ rBufferObject();
+ virtual ~rBufferObject();
+
+ virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) override;
+ virtual void unbindBuffer() override;
+
+ virtual void useBuffer() const override;
+
+ virtual void clearBuffer() const override;
+
+ void updateSize(unsigned int _width, unsigned int _height) override;
+
+protected:
+ unsigned int width=0, height = 0;
+
+};
+
+++ /dev/null
-#include "tBuffer.h"
-
-#include <GL\glew.h>
-#include "../Shader.h"
-
-
-tBuffer::tBuffer(unsigned int _dim)
-{
- buffer_target = GL_FRAMEBUFFER;
-
- /*gen Buffer*/
- glGenBuffers(1, &handle);
-
-
- /*gen Texture*/
- textures = new Texture[_dim];
-}
-
-
-tBuffer::~tBuffer()
-{
- delete textures;
- glDeleteBuffers(1, &handle);
-}
-
-tBuffer::operator unsigned int() const
-{
- return handle;
-}
-
-unsigned int tBuffer::getDim() const
-{
- return dim;
-}
-
-Texture* tBuffer::getTexture(unsigned int i) const
-{
- return &textures[i];
-}
-
-void tBuffer::bindBuffer()
-{
- glBindFramebuffer(buffer_target, handle);
- for (unsigned int i = 0; i < dim; i++)
- {
- textures[i].bindTexture();
- glFramebufferTexture2D(buffer_target, GL_COLOR_ATTACHMENT0 + i, textures[i].getTTarget(), textures[i], 0);
- }
-
-}
-
-void tBuffer::unbindBuffer()
-{
- for (unsigned int i = 0; i < dim; i++)
- {
- textures[i].unbindTexture();
- }
- glDeleteBuffers(1, &handle);
- glGenBuffers(1, &handle);
-
-}
-
-void tBuffer::useBuffer() const
-{
- glBindFramebuffer(buffer_target, handle);
-}
\ No newline at end of file
+++ /dev/null
-#pragma once
-#include "Texture.h"
-
-class tBuffer
-{
-public:
- tBuffer(unsigned int dim=1);
- virtual ~tBuffer();
-
- virtual void bindBuffer();
- virtual void unbindBuffer();
- virtual void useBuffer() const;
-
- operator unsigned int() const;
-
- unsigned int getDim() const;
- Texture* getTexture(unsigned int i = 0) const;
-
- unsigned int dim;
- Texture* textures = nullptr;
-protected:
- unsigned int handle;
- unsigned int buffer_target;
-
-
-
-};
-
FreeImage_Unload((FIBITMAP*)data);
}
-void tImage::bindTexture()
+void tImage::bindTexture(unsigned int _width, unsigned int _height)
{
Texture::bindTexture();
}
-void tImage::useTexture() const
+void tImage::useTexture(unsigned int _unit) const
{
/* bind Texture*/
- int unit = 0;
- glActiveTexture(GL_TEXTURE0 + unit);
+ glActiveTexture(GL_TEXTURE0 + _unit);
glBindTexture(texture_target, handle);
- Shader::gActive()->setUniformLocation("uColorTexture", unit);
+ Shader::gActive()->setUniformLocation("uColorTexture", _unit);
/* bind Material*/
Shader::gActive()->setUniformLocation("material", material);
tImage(const std::string& path, const vec4& material);
virtual ~tImage();
- virtual void bindTexture() override;
- virtual void useTexture() const override;
+ virtual void bindTexture(unsigned int width = 0, unsigned int height = 0) override;
+ virtual void useTexture(unsigned int i=0) const override;
operator std::string() const;
#include "../Graphix/Shader.h"
#include "../Graphix/ViewPort.h"
+#include "../Graphix/Textures.h"
+#include "../Graphix/Model.h"
#include "../Message.h"
#include "../Events.h"
bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0));
+
+ blur = new fBufferObject(2);
+ render = new fBufferObject(1);
+
+ blur->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+ render->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+
+ render->clearBuffer();
}
void Scene::draw() const
{
+ //render->useBuffer();
viewPort.useViewPort();
//Skybox
}
SkyBox.draw();
-
for (auto i = SceneObjects.cbegin(); i != SceneObjects.cend(); ++i)
{
(*i)->draw();
}
+
+ //render->clearBuffer();
+ //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ //Shader::gBasicTexture()->useShader();
+ //render->getTexture(0)->useTexture(0);
+ //Model::getPlaneModel()->drawModel(mat4(1.f));
}
class ViewPort;
class Sky;
class Shader;
+class fBufferObject;
class Scene
{
btSequentialImpulseConstraintSolver* bt_solver;
btCollisionWorld* bt_collision_world;
btDiscreteDynamicsWorld* bt_dynamics_world;
+
+ fBufferObject* render;
+ fBufferObject* blur;
};
<ClCompile Include="Graphix\Model\Plane.cpp" />\r
<ClCompile Include="Graphix\Model\SkyBox.cpp" />\r
<ClCompile Include="Graphix\PointLight.cpp" />\r
- <ClCompile Include="Graphix\Textures\tBuffer.cpp" />\r
+ <ClCompile Include="Graphix\Textures\fBufferObject.cpp" />\r
+ <ClCompile Include="Graphix\Textures\rBufferObject.cpp" />\r
<ClCompile Include="Graphix\Textures\Texture.cpp" />\r
<ClCompile Include="Scene\EventBox.cpp" />\r
<ClCompile Include="Scene\Level.cpp" />\r
</ItemGroup>\r
<ItemGroup>\r
<ClInclude Include="Average.h" />\r
+ <ClInclude Include="Graphix\Textures\BufferObject.h" />\r
<ClInclude Include="Graphix\Debug.h" />\r
<ClInclude Include="Graphix\Model.h" />\r
<ClInclude Include="Events.h" />\r
<ClInclude Include="Graphix\Model\SkyBox.h" />\r
<ClInclude Include="Graphix\PointLight.h" />\r
<ClInclude Include="Graphix\Textures.h" />\r
- <ClInclude Include="Graphix\Textures\tBuffer.h" />\r
+ <ClInclude Include="Graphix\Textures\fBufferObject.h" />\r
+ <ClInclude Include="Graphix\Textures\rBufferObject.h" />\r
<ClInclude Include="Graphix\Textures\Texture.h" />\r
<ClInclude Include="Scene.h" />\r
<ClInclude Include="Scene\EventBox.h" />\r
<ClCompile Include="Graphix\Textures\tImage.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
- <ClCompile Include="Graphix\Textures\tBuffer.cpp">\r
+ <ClCompile Include="Graphix\Textures\fBufferObject.cpp">\r
+ <Filter>Source Files</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="Graphix\Textures\rBufferObject.cpp">\r
<Filter>Source Files</Filter>\r
</ClCompile>\r
</ItemGroup>\r
<ClInclude Include="Graphix\Textures\tImage.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
- <ClInclude Include="Graphix\Textures\tBuffer.h">\r
+ <ClInclude Include="Graphix\Textures\BufferObject.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="Graphix\Textures\fBufferObject.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="Graphix\Textures\rBufferObject.h">\r
<Filter>Header Files</Filter>\r
</ClInclude>\r
</ItemGroup>\r
//Fragment Shader
-#version 330
+#version 330 core
//in worldNormal;
in vec2 fUVs;
+layout(location = 0) out vec4 gl_FragColor;
+
uniform sampler2D uColorTexture;
void main()
in vec3 PointLightPosition1, DirectionalLightDirection1;
+layout (location = 0) out vec4 gl_FragColor;
+
uniform sampler2D uColorTexture;
uniform vec4 material; //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3)