Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/VertexArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void VertexArray::AddBuffer(const VertexBuffer &vb, const VertexBufferLayout &la
{
const auto &element = elements[i];
glEnableVertexAttribArray(i);
glVertexAttribPointer(i, element.count, element.type, element.normalize, layout.GetStride(), (const void *)offSet);
glVertexAttribPointer(i, element.count, element.type, element.normalize, layout.GetStride(), 0);
offSet += element.count * VertexBufferElement::GetSizeOfType(element.type);
}
}
9 changes: 5 additions & 4 deletions src/VertexBufferLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct VertexBufferElement
case GL_UNSIGNED_BYTE:
return 1;
}
// std::cout << type << std::endl;
assert(false);
return 0;
}
Expand All @@ -37,7 +38,7 @@ class VertexBufferLayout
template <typename T>
void Push(unsigned int count)
{
static_assert(false);
static_assert(true, "Assertion Failed");
}

inline const std::vector<VertexBufferElement> GetElements() const { return m_Elements; }
Expand All @@ -47,20 +48,20 @@ class VertexBufferLayout
template <>
void VertexBufferLayout::Push<float>(unsigned int count)
{
m_Elements.push_back({count, GL_FLOAT, GL_FALSE});
m_Elements.push_back({GL_FLOAT, count, GL_FALSE});
m_Stride += count * VertexBufferElement::GetSizeOfType(GL_FLOAT);
}

template <>
void VertexBufferLayout::Push<unsigned int>(unsigned int count)
{
m_Elements.push_back({count, GL_UNSIGNED_INT, GL_FALSE});
m_Elements.push_back({GL_UNSIGNED_INT, count, GL_FALSE});
m_Stride += count * VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT);
}

template <>
void VertexBufferLayout::Push<unsigned char>(unsigned int count)
{
m_Elements.push_back({count, GL_UNSIGNED_BYTE, GL_TRUE});
m_Elements.push_back({GL_UNSIGNED_BYTE, count, GL_TRUE});
m_Stride += count * VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE);
}
Binary file modified src/a.out
Binary file not shown.
18 changes: 9 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Renderer.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
// #include "VertexArray.h"
#include "VertexArray.h"

struct ShaderProgramSource
{
Expand Down Expand Up @@ -141,14 +141,14 @@ int main()
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);

// VertexArray va;
VertexArray va;
VertexBuffer vb(points, 12 * sizeof(float));
// VertexBufferLayout layout;
// layout.Push<float>(3);
// va.AddBuffer(vb, layout);
VertexBufferLayout layout;
layout.Push<float>(3);
va.AddBuffer(vb, layout);

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
// glEnableVertexAttribArray(0);
// glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
IndexBuffer ib(indices, 6);

struct ShaderProgramSource shaderSource = ParseShader("Basic.shader");
Expand All @@ -170,8 +170,8 @@ int main()

glUseProgram(shader);
glUniform4f(location, r, 0.7f, 0.5f, 1.0f);
glBindVertexArray(vao);
// va.Bind();
// glBindVertexArray(vao);
va.Bind();
ib.Bind();
if (r > 1.0f)
increment = -0.05;
Expand Down