summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2022-11-20 01:03:31 -0500
committerrealtradam <[email protected]>2022-11-20 01:03:31 -0500
commit1ddfb9865a985ebc140fb92467bf67cceca7683e (patch)
tree380568a440b9c0292b15351eccfe28ab6b2557ce /src
parent9c03630e9f7bd99be2bb541714d72343b61c8c88 (diff)
downloadOgle-1ddfb9865a985ebc140fb92467bf67cceca7683e.tar.gz
Ogle-1ddfb9865a985ebc140fb92467bf67cceca7683e.zip
drawing rectangles
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/src/main.cpp b/src/main.cpp
index bdd92d5..82e7fa0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,16 +24,16 @@ void main()
}
)";
-//float vertices[] = {
-// 0.5f, 0.5f, 0.0f, // top right
-// 0.5f, -0.5f, 0.0f, // bottom right
-// -0.5f, -0.5f, 0.0f, // bottom left
-// -0.5f, 0.5f, 0.0f // top left
-//};
-//unsigned int indices[] = { // note that we start from 0!
-// 0, 1, 3, // first triangle
-// 1, 2, 3 // second triangle
-//};
+float vertices[] = {
+ 0.5f, 0.5f, 0.0f, // top right
+ 0.5f, -0.5f, 0.0f, // bottom right
+ -0.5f, -0.5f, 0.0f, // bottom left
+ -0.5f, 0.5f, 0.0f // top left
+};
+unsigned int indices[] = { // note that we start from 0!
+ 0, 1, 3, // first triangle
+ 1, 2, 3 // second triangle
+};
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
@@ -65,14 +65,6 @@ int main() {
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
- // Vertex Input
- float vertices[] = {
- -0.5f, -0.5f, 0.0f,
- 0.5f, -0.5f, 0.0f,
- 0.0f, 0.5f, 0.0f
- };
-
-
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER); // create a blank shader
glShaderSource(vertexShader, 1, &vertexShaderSource, NULL);
@@ -122,16 +114,23 @@ int main() {
glDeleteShader(vertexShader); // we dont need these anymore once they are linked in the shader program
glDeleteShader(fragmentShader);
- unsigned int VBO, VAO;
+ unsigned int VBO, VAO, EBO;
glGenBuffers(1, &VBO); // generate the buffer
+ glGenBuffers(1, &EBO);
+
glGenVertexArrays(1, &VAO); // generate array
glBindVertexArray(VAO); // bind array to apply "settings" to it
+
glBindBuffer(GL_ARRAY_BUFFER, VBO); // bind(activate) the buffer to the ARRAY_BUFFER
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); // upload the data
+ //
+ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
+ glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); // configure how the vertex array looks
glEnableVertexAttribArray(0);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// game loop
while(!glfwWindowShouldClose(window))
@@ -144,7 +143,8 @@ int main() {
glUseProgram(shaderProgram); // this will activate the shader and use them for all subsequent shader and render calls
glBindVertexArray(VAO); // activate the preconfigured settings
- glDrawArrays(GL_TRIANGLES, 0, 3); // :)
+ glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); // :)
+ glBindVertexArray(0);
glfwSwapBuffers(window);
glfwPollEvents();