diff --git a/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj b/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj index 4ef2f0f..c62164a 100644 --- a/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj +++ b/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj @@ -160,10 +160,13 @@ + + + diff --git a/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj.filters b/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj.filters index 6b1c967..dca02fe 100644 --- a/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj.filters +++ b/NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj.filters @@ -24,6 +24,12 @@ Header Files + + Header Files + + + Header Files + @@ -35,6 +41,9 @@ Source Files + + Source Files + diff --git a/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.cpp b/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.cpp new file mode 100644 index 0000000..881a715 --- /dev/null +++ b/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.cpp @@ -0,0 +1,89 @@ +/* +MIT License + +Copyright (c) 2017 Chris McArthur, prince.chrismc(at)gmail(dot)com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#include "Shader.h" +#include "DrawableObject.h" + + +DrawableObject::DrawableObject(const std::vector verticies, const std::vector colors, const std::vector indicies) +{ + ShaderLinker* shaderProgram = &ShaderLinker::GetInstance(); + GLuint PositonIndex = shaderProgram->GetAttributeLocation("position"); + GLuint ColorIndex = shaderProgram->GetAttributeLocation("color"); + + glGenVertexArrays(1, &m_VAO); + glBindVertexArray(m_VAO); + + glGenBuffers(1, &m_Verticies); + glBindBuffer(GL_ARRAY_BUFFER, m_Verticies); + glBufferData(GL_ARRAY_BUFFER, verticies.size() * sizeof(glm::vec3), &verticies.front(), GL_STATIC_DRAW); + glVertexAttribPointer(PositonIndex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); + glEnableVertexAttribArray(PositonIndex); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glGenBuffers(1, &m_Colors); + glBindBuffer(GL_ARRAY_BUFFER, m_Colors); + glBufferData(GL_ARRAY_BUFFER, colors.size() * sizeof(glm::vec3), &colors.front(), GL_STATIC_DRAW); + glVertexAttribPointer(ColorIndex, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0); + glEnableVertexAttribArray(ColorIndex); + glBindBuffer(GL_ARRAY_BUFFER, 0); + + glGenBuffers(1, &m_Indicies); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Indicies); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicies.size() * sizeof(GLuint), &indicies.front(), GL_STATIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + + glBindVertexArray(0); + + m_NumVertices = (GLsizei)verticies.size(); + m_NumIndicies = (GLsizei)indicies.size(); +} + +void DrawableObject::Delete() +{ + glDeleteBuffers(1, &m_Verticies); + glDeleteBuffers(1, &m_Colors); + glDeleteBuffers(1, &m_Indicies); + glDeleteVertexArrays(1 ,&m_VAO); +} + +void DrawableObject::Draw(const RenderMode& render_mode) +{ + switch (render_mode) + { + case RenderMode::POINTS: + glBindVertexArray(m_VAO); + glDrawArrays(GL_POINTS, 0, m_NumVertices); + glBindVertexArray(0); + break; + + case RenderMode::TRIANGLES: + glBindVertexArray(m_VAO); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Indicies); + glDrawElements(GL_TRIANGLES, m_NumIndicies, GL_UNSIGNED_INT, NULL); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindVertexArray(0); + break; + } +} diff --git a/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.h b/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.h new file mode 100644 index 0000000..b153c82 --- /dev/null +++ b/NeverGreenGrove/NeverGreenGrove/src/DrawableObject.h @@ -0,0 +1,49 @@ +/* +MIT License + +Copyright (c) 2017 Chris McArthur, prince.chrismc(at)gmail(dot)com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include + +#include +#include "glm\vec3.hpp" + +#include "RenderMode.h" + +class DrawableObject +{ + public: + DrawableObject(const std::vector verticies, const std::vector colors, const std::vector indicies); + virtual void Draw(const RenderMode& render_mode); + void Delete(); + + protected: + GLuint m_VAO; + GLuint m_Verticies; + GLuint m_Colors; + GLuint m_Indicies; + + GLsizei m_NumVertices; + GLsizei m_NumIndicies; +}; \ No newline at end of file diff --git a/NeverGreenGrove/NeverGreenGrove/src/RenderMode.h b/NeverGreenGrove/NeverGreenGrove/src/RenderMode.h new file mode 100644 index 0000000..4f6390c --- /dev/null +++ b/NeverGreenGrove/NeverGreenGrove/src/RenderMode.h @@ -0,0 +1,29 @@ +/* +MIT License + +Copyright (c) 2017 Chris McArthur, prince.chrismc(at)gmail(dot)com + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include + +enum class RenderMode { POINTS = GL_POINTS, LINES = GL_LINES, TRIANGLES = GL_TRIANGLES }; \ No newline at end of file