summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2020-09-15 13:44:04 +0200
committerraysan5 <[email protected]>2020-09-15 13:44:04 +0200
commitc5c156d65e3a12e5b9abbf93c3a0cd51d29a5971 (patch)
treecb6108e3381c64d659651e6fb6ba39aec29dd72a /src
parent2d96196d254a6199b3aca29957e7970ac1cfbbaa (diff)
downloadraylib-c5c156d65e3a12e5b9abbf93c3a0cd51d29a5971.tar.gz
raylib-c5c156d65e3a12e5b9abbf93c3a0cd51d29a5971.zip
Review GenDrawCube() and GenDrawQuad()
Better organized and commented
Diffstat (limited to 'src')
-rw-r--r--src/rlgl.h112
1 files changed, 58 insertions, 54 deletions
diff --git a/src/rlgl.h b/src/rlgl.h
index a2c81a6c..287dc7b3 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -4467,33 +4467,34 @@ static void GenDrawQuad(void)
unsigned int quadVBO = 0;
float vertices[] = {
- // Positions // Texture Coords
- -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
- -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
- 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
- 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
+ // Positions Texcoords
+ -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
+ -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
+ 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
+ 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
};
- // Set up plane VAO
+ // Gen VAO to contain VBO
glGenVertexArrays(1, &quadVAO);
- glGenBuffers(1, &quadVBO);
glBindVertexArray(quadVAO);
- // Fill buffer
+ // Gen and fill vertex buffer (VBO)
+ glGenBuffers(1, &quadVBO);
glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices, GL_STATIC_DRAW);
- // Link vertex attributes
+ // Bind vertex attributes (position, texcoords)
glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)0); // Positions
glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float)));
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5*sizeof(float), (void *)(3*sizeof(float))); // Texcoords
// Draw quad
glBindVertexArray(quadVAO);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindVertexArray(0);
+ // Delete buffers (VBO and VAO)
glDeleteBuffers(1, &quadVBO);
glDeleteVertexArrays(1, &quadVAO);
}
@@ -4505,60 +4506,62 @@ static void GenDrawCube(void)
unsigned int cubeVBO = 0;
float vertices[] = {
- -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
- 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
- 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
- 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
- -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
- -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,
- -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
- 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
- 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
- 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
- -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,
- -1.0f, -1.0f, 1.0f, 0.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0.0f
};
- // Set up cube VAO
+ // Gen VAO to contain VBO
glGenVertexArrays(1, &cubeVAO);
+ glBindVertexArray(cubeVAO);
+
+ // Gen and fill vertex buffer (VBO)
glGenBuffers(1, &cubeVBO);
-
- // Fill buffer
glBindBuffer(GL_ARRAY_BUFFER, cubeVBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- // Link vertex attributes
+ // Bind vertex attributes (position, normals, texcoords)
glBindVertexArray(cubeVAO);
glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0);
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)0); // Positions
glEnableVertexAttribArray(1);
- glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float)));
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(3*sizeof(float))); // Normals
glEnableVertexAttribArray(2);
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float)));
+ glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8*sizeof(float), (void *)(6*sizeof(float))); // Texcoords
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
@@ -4567,6 +4570,7 @@ static void GenDrawCube(void)
glDrawArrays(GL_TRIANGLES, 0, 36);
glBindVertexArray(0);
+ // Delete VBO and VAO
glDeleteBuffers(1, &cubeVBO);
glDeleteVertexArrays(1, &cubeVAO);
}