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();
}

View file

@ -0,0 +1,9 @@
#version 330 core
in vec3 oCol;
out vec4 FragColor;
void main()
{
FragColor = vec4(oCol, 1.0f);
}

View file

@ -1,7 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aCol;
out vec3 oCol;
void main()
{
oCol = aCol;
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
}