Posts

Showing posts from August, 2015

2.2: Adding Some Texture

Image
This time we are adding a texture to the triangle.  We'll have to add two main pieces of data:  texture coordinates and texture data.  Texture coordinates are the same as vertex positions in that they may be described in 4 dimensions.  When we talk about a position (coordinate) on the texture itself, the vectors are named s, t, r, and q.  An alternative naming convention is to use u, v, w in place of s, t, and r.  I believe the fourth vector is sometimes called x instead of q, (but don't quote me on that).  Also, to complicate the naming convention further, GLSL does not use r, but p for the third vector because r is already taken by red in rgba.  All that to say that GLSL texture coordinates are named s, t, p, and q, but OpenGL names them s, t, r, and q.  Yes, yet another OpenGL inconsistency that can get a little confusing if you don't know about it. Adding a texture is going to take several steps--far more non-trivial than adding color.  First, create a new target call

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 outgoing fragments. Bef