You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book-src/basics/001-drawing-a-triangle.md
+69-1Lines changed: 69 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,6 +97,12 @@ to make it the active VAO. This is a _context wide_ effect, so now all GL
97
97
functions in our GL context will do whatever they do with this VAO as the VAO to
98
98
work with.
99
99
100
+
As a note: you can also bind the value 0 at any time, which clears the vertex
101
+
array binding. This might sound a little silly, but it can help spot bugs in
102
+
some situations. If you have no VAO bound when you try to call VAO affected
103
+
functions it'll generate an error, which usually means that you forgot to bind
104
+
the VAO that you really did want to affect.
105
+
100
106
### Generate A Vertex Buffer Object
101
107
102
108
To actually get some bytes of data to the video card we need a [Vertex Buffer
@@ -119,14 +125,76 @@ unsafe {
119
125
}
120
126
```
121
127
122
-
Now that we have a buffer, we can bind it to the binding target that we want. [`glBindBuffer`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBindBuffer.xhtml) takes a target name and a buffer. As you can see on that page, there's a whole lot of options, but for now we just want `GL_ARRAY_BUFFER`.
128
+
Now that we have a buffer, we can bind it to the binding target that we want.
takes a target name and a buffer. As you can see on that page, there's a whole
131
+
lot of options, but for now we just want to use the `GL_ARRAY_BUFFER` target.
123
132
124
133
```rust
125
134
unsafe {
126
135
glBindBuffer(GL_ARRAY_BUFFER, vbo);
127
136
}
128
137
```
129
138
139
+
And, similar to the VAO's binding process, now that our vertex buffer object is
140
+
bound to the the `GL_ARRAY_BUFFER` target, all commands using that target will
141
+
operate on the buffer that we just made.
142
+
143
+
(Is this whole binding thing a dumb way to design an API? Yeah, it is. Oh well.)
144
+
145
+
Now that we have a buffer bound as the `GL_ARRAY_BUFFER`, we can finally use [`glBufferData`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml) to actually send over some data bytes. We have to specify the binding target we want to buffer to, the `isize` of the number of bytes we want to buffer, the const pointer to the start of the data we're buffering, and the usage hint.
146
+
147
+
Most of that is self explanatory, except the usage hint. Basically there's
148
+
memory that's faster or slower for the GPU to use or the CPU to use. If we hint
149
+
to the GPU how we intend to use the data and how often we intend to update it
150
+
then it has a chance to make a smarter choice of where to put the data. You can
151
+
see all the options on the `glBufferData` spec page. For our first demo we want
152
+
`GL_STATIC_DRAW`, since we'll just be sending the data once, and then GL will
0 commit comments