JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

Chapter 7. OpenGL Shading Language API

In 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:

1.
Create one or more (empty) shader objects with glCreateShader.

2.
Provide source code for these shaders with glShaderSource.

3.
Compile each of the shaders with glCompileShader.

4.
Create a program object with glCreateProgram.

5.
Attach all the shader objects to the program object with glAttachShader.

6.
Link the program object with glLinkProgram.

7.
Install the executable program as part of OpenGL's current state with glUseProgram.

8.
If the shaders use user-defined uniform variables, query the locations of these variables with glGetUniformLocation and then set their values with glUniform.

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.


Previous Page
Next Page



R7
JavaScript EditorAjax Editor     JavaScript Editor