Graphics Programs Reference
In-Depth Information
+ "precision highp float; \n"
+ "#else \n"
+ "precision mediump float; \n"
+ "#endif \n"
+ "varying vec2 vCoord; \n"
+ "varying vec4 vColor; \n"
+ "uniform sampler2D uSampler; \n"
+ "void main() { \n"
+ " vec4 textureColor; \n"
+ " textureColor = texture2D(uSampler,vCoord); \n"
+ " gl_FragColor = vColor + textureColor; \n"
+ "} \n";
Cubemap Textures
Cubemap textures are another type of texture in ES 2.0. They are called cubemap
textures, because a cubemap texture is composed of six 2D textures in which each
texture represents one of the six faces of a cube.
Texels from a cubemap texture are fetched in a complex way, compared to how they
are fetched from a 2D texture. However, defining a texture coordinate array for a
cubemap texture is a lot easier than doing so for a 2D texture.
Listing 5-9 contains array definitions from the GLCUBEMAPTEXTURE application
(the output is seen in Figure 3-5) from the source code for this chapter ( Chapter5/ ). This application demonstrates using a cubemap tex-
As indicated in Listing 5-9 , cubeVFA is the vertex coordinate array, cubeISA is
the index array, and cubeTFA is the texture coordinate array. Arrays cubeVFA and
cubeTFA are similar, except that the texture coordinates in cubeTFA are filled with
ones. Compared to the (s, t) coordinates used in 2D textures, cubemap textures
use an additional coordinate, because fetching texels from a cubemap texture requires
3D vectors. Please note that we do not have to worry about the underlying process
that does so. Fetching texels automatically takes place using the built-in ES 2.0 func-
tion textureCube , called inside the fragment shader.
Listing 5-9. GL CUBEMAP TEXTURE/src/com/apress/android/glcubemaptex-
Search WWH ::

Custom Search