Posts

Showing posts with the label glVertexAttribPointer()

2.1: Custom Color

Image
Last time, we talked about defining a vertex with a position and color, but we only created three vertices using a simple array of location data.  This time we'll create a struct that has position and color and make an array with three of those structs.  We'll send this to the VBO and then create two vertex attribute pointers--this time utilizing the offset parameter in glVertexAttribPointer( ) to specify the location of the color data. We'll have to update the shader, too.  The vertex shader will need to have a second input for the color, but it will also need an output.  When an output from the vertex shader and the input of fragment shader have the same name, they automatically connect to one another.  Why would we want to do that though?  It is the fragment shader that adds color to the geometry that we draw; however, data has to be passed through the vertex shader to get to the fragment shader.  Once there, we already have an output for each out...

2.0: VBO's and VAO's

Image
Now that we have a working renderer, we can go back and revaluate some of the concepts we touched upon in greater detail.  The first is going to be the vertex buffer object (VBO).  OpenGL objects are reserved spaces of memory that contain user specified data such as vertex locations, pointers, or inaccessible data that you can only refer to by handles (like shaders). VBO's may be used for raw data associated with vertices--x, y, z, w positions; r, g, b, a colors; s, t, r, q texture coordinates; and vertex indices.  Our first program used a hard coded position so we didn't need a VBO; however, this method is only useful for drawing one vertex.  To draw multiple vertices, we will load the VBO with the vertex data, and use vertex array object (VAO) to tell the shader where it can find the data it needs for drawing. A VAO then, is an OpenGL object that stores pointers to to each input attribute in a vertex shader.  There are two major ways to create pointers: ...