JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
Previous Page
Next Page

7.14. Summary

The set of function calls added to OpenGL to create and manipulate shaders is actually quite small. The interface mimics the software development process followed by a C/C++ programmer. To install and use OpenGL shaders, do the following:

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

Provide source code for these shaders with glShaderSource.

Compile each of the shaders with glCompileShader.

Create a program object with glCreateProgram.

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

Link the program object with glLinkProgram.

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

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

User-defined attribute variables can be explicitly associated with a generic vertex attribute index with glBindAttribLocation, or such associations can be assigned implicitly at link time and queried with glGetAttribLocation. Generic vertex attribute values can then be supplied by the application a vertex at a time with one of the variants of glVertexAttrib or as vertex arrays by using glVertexAttribPointer and glEnableVertexArrayPointer in conjunction with standard OpenGL commands to draw vertex arrays.

A number of query functions obtain information about shader and program objects.

Previous Page
Next Page

JavaScript EditorAjax Editor     JavaScript Editor