Graphics Reference
In-Depth Information
float red, green, blue, alpha;
. . .
fwrite( &red, 4, 1, fp );
fwrite( &green, 4, 1, fp );
fwrite( &blue, 4, 1, fp );
fwrite( &alpha, 4, 1, fp );
}
}
}
Note that glman expects the binary byte-ordering in a raw texture file to
be consistent with the Intel x86 architecture. If you write raw texture files from
a pre-Intel Macintosh, you must reverse the byte ordering yourself.
The second argument in the Texture2D and Texture3D commands is
the OpenGL texture unit to assign this texture to. You then need to tell your
shaders what that texture number is. For example, the GLIB Texture command
might specify that a texture is to use texture unit 7 by
Program Texture uTexUnit 7
and your fragment shader might include code that picks up the value of
uTexUnit as the unit for the sampler2D texture with
uniform sampler2D uTexUnit;
in vec2 vST; // from the vertex shader
out vec4 fFragColor;
void
main( )
{
vec4 rgba = texture( uTexUnit, vST );
fFragColor = vec4( rgba.rgb, 1. );
}
You should not hard-code the value 7 in the Texture2D function call—the
compiler won't let you! Furthermore, don't use texture units 2 and 3 yourself;
glman uses these as default values to tell your shaders about its built-in 2D and
3D noise textures.
Using Noise
As we will see in Chapter 10, glman automatically creates a 3D noise texture
and places it into Texture Unit 3. Your vertex, tessellation, geometry, or frag-
ment shader can get at it through the pre-created uniform variable called
Noise3 . You can reference it in your shader as
Search WWH ::




Custom Search