Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Adding light weight OOGL #1

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NeverGreenGrove/NeverGreenGrove/NeverGreenGrove.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,13 @@
<Text Include="README.md" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\DrawableObject.h" />
<ClInclude Include="src\GlfwWindow.h" />
<ClInclude Include="src\RenderMode.h" />
<ClInclude Include="src\Shader.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\DrawableObject.cpp" />
<ClCompile Include="src\GlfwWindow.cpp" />
<ClCompile Include="src\Shader.cpp" />
<ClCompile Include="src\NeverGreenGrove.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<ClInclude Include="src\Shader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\DrawableObject.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\RenderMode.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\GlfwWindow.cpp">
Expand All @@ -35,6 +41,9 @@
<ClCompile Include="src\Shader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\DrawableObject.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="shaders\fragment.shader">
Expand Down
89 changes: 89 additions & 0 deletions NeverGreenGrove/NeverGreenGrove/src/DrawableObject.cpp
Original file line number Diff line number Diff line change
@@ -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<glm::vec3> verticies, const std::vector<glm::vec3> colors, const std::vector<GLuint> 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;
}
}
49 changes: 49 additions & 0 deletions NeverGreenGrove/NeverGreenGrove/src/DrawableObject.h
Original file line number Diff line number Diff line change
@@ -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 <vector>

#include <gl\glew.h>
#include "glm\vec3.hpp"

#include "RenderMode.h"

class DrawableObject
{
public:
DrawableObject(const std::vector<glm::vec3> verticies, const std::vector<glm::vec3> colors, const std::vector<GLuint> 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;
};
29 changes: 29 additions & 0 deletions NeverGreenGrove/NeverGreenGrove/src/RenderMode.h
Original file line number Diff line number Diff line change
@@ -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 <gl\GL.h>

enum class RenderMode { POINTS = GL_POINTS, LINES = GL_LINES, TRIANGLES = GL_TRIANGLES };