Added basic object wrapper for VAOs

This commit is contained in:
Robert 2021-01-20 16:51:55 +01:00
parent c3e49cd78e
commit 8921957161
7 changed files with 162 additions and 17 deletions

View file

@ -37,20 +37,36 @@ int main(int argc, char** argv)
oglu::LoadGLLoader((GLADloadproc)glfwGetProcAddress);
oglu::SetViewport(0, 0, windowSize, windowSize);
float vertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom left
-0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f // top left
};
unsigned int indices[] = {
0, 1, 3, // first triangle
1, 2, 3 // second triangle
};
oglu::VertexAttribute topology[] = {
{ 0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0 }
{ 0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0 },
{ 1, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)(3 * sizeof(float)) }
};
oglu::Object triangle(vertices, sizeof(vertices), nullptr, 0, topology, sizeof(topology));
oglu::Shader shader("shaders/vertexShader.vert", "");
oglu::Shader* shader;
try
{
shader = new oglu::Shader("shaders/vertexShader.vert", "shaders/fragmentShader.frag");
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return -1;
}
oglu::Object square(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
while (!glfwWindowShouldClose(window))
{
@ -58,6 +74,9 @@ int main(int argc, char** argv)
oglu::ClearScreen(GL_COLOR_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f));
shader->Use();
square.BindAndDraw();
glfwSwapBuffers(window);
glfwPollEvents();
}