Chapter 7. OpenGL Shading Language APIIn support of the OpenGL Shading Language, more than 30 new entry points were added to OpenGL in version 2.0. This set of API calls is referred to throughout this book as the OPENGL SHADING LANGUAGE API. In this chapter, we look at the OpenGL entry points that have been added to create, load, compile, and link shaders, as well as the entry points that have been added for passing generic vertex attributes and uniform variables to shaders. Reference pages for all of the OpenGL Shading Language API entry points are found in Appendix B. At the end of this chapter, we discuss the application code that is needed to create and use the brick shader presented in Chapter 6. If you just can't wait, go ahead and sneak a peek at Section 7.13, and then come back here to learn the details of the API. Here is an overview of creating and using OpenGL shaders:
If the vertex shader uses user-defined attribute variables, the application must provide values for them, using OpenGL API calls that place attribute values in generic, numbered vertex attribute locations. Before such attribute data is passed to the shader, the index of the generic vertex attribute should be associated with an attribute variable in a vertex shader in one of two ways. Applications can create this association explicitly by calling glBindAttribLocation before linking. Alternatively, if no explicit association is made, OpenGL makes these associations automatically during linking. An application can query the assignment that was made with glGetAttribLocation. Thereafter, generic vertex attributes can be passed to a vertex shader with glVertexAttrib or with glVertexAttribPointer and glEnableVertexArrayPointer in conjunction with standard OpenGL commands to draw vertex arrays. |