Graphics Reference
In-Depth Information
All the operations of a fragment shader—color computation, texturing, color
arithmetic, and fog—come together to set these variables. They are
vec4 fFragColor —the color of the pixels.
float gl_FragDepth —the depth of the pixels.
Passing Data from Your Application into Shaders
As you write any program with the OpenGL API, even if you don't intend
that program to use GLSL shaders, you create data that the system will use in
creating a scene. This is generally graphical data that describes the scene. For
example, you can specify the color for each vertex, or you can create an array
of vertices and a parallel array with data such as elevations, temperature, or
any measured data. The data could be used in fixed-function operations by
manipulating primitives based on your data, or with shader-based operations
by puting the data into user-deined atribute or uniform data that you can
access within the shader function(s). In these sections, we describe how you
can create atribute or uniform data for shaders, and we give some examples
that show these in action. In Chapter 9, we describe how you can create sam-
pler data for shaders.
Defining Attribute Variables in Your Application
Atribute variables are a way to provide per-vertex data to a vertex shader.
These are only available to a vertex shader. If any vertex-speciic atribute data
needs to be used by a later shader, the vertex shader must first convert it to an
out variable so the later shader can take it as an in variable. Here we describe
the general approach to defining variables that describe properties of an indi-
vidual vertex in your model.
Besides the usual atribute data such as the coordinates, normal, color,
or texture coordinates of a vertex, you may also need to define other data to
associate with a vertex. OpenGL lets applications deine custom atributes to
pass to a vertex shader. Each vertex atribute has an indexed location and can
contain up to four values.
As with uniform variables, you need to determine the symbol table loca-
tion of an atribute variable before you can set it:
GLuint glGetAttribLocation( GLuint program,
GLchar * attribName );
Search WWH ::




Custom Search