aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/main.c b/main.c
index 8ac0ca2..c7a156b 100644
--- a/main.c
+++ b/main.c
@@ -8,18 +8,19 @@
#include "hello_vert.h"
#include "hello_frag.h"
-void prepare_tri(GLuint* VBO, GLuint* VAO) {
+void prepare_tri() {
const float vertices[] = {
- -0.5f, -0.5f, 0.0f,
- 0.5f, -0.5f, 0.0f,
- 0.0f, 0.5f, 0.0f,
+ -1, -1, 0,
+ 3, -1, 0,
+ -1, 3, 0,
};
// initialize vertex {buffer,attribute} object buffers
- glGenBuffers(1, VBO);
- glBindBuffer(GL_ARRAY_BUFFER, *VBO);
- glGenBuffers(1, VAO);
- glBindVertexArray(*VAO);
+ GLuint VBO, VAO;
+ glGenBuffers(1, &VBO);
+ glBindBuffer(GL_ARRAY_BUFFER, VBO);
+ glGenVertexArrays(1, &VAO);
+ glBindVertexArray(VAO);
// copy vertex data into VBO
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
@@ -27,6 +28,10 @@ void prepare_tri(GLuint* VBO, GLuint* VAO) {
// set VAO pointers
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
+
+ // draw (only) this triangle
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
+ glBindVertexArray(VAO);
}
int main(int argc, char** argv) {
@@ -49,8 +54,7 @@ int main(int argc, char** argv) {
glewInit();
// create single triangle
- GLuint VBO, VAO;
- prepare_tri(&VBO, &VAO);
+ prepare_tri();
// prepare shaders
GLuint shader = link_shaders(
@@ -62,11 +66,7 @@ int main(int argc, char** argv) {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
- glClearColor(1.f, 0.f, 1.f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-
glUseProgram(shader);
- glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);