Pro OpenGL ES for iOS

(singke) #1

CHAPTER 10: OpenGL ES 2, Shaders, and... (^323)
void main()
{
vec4 newColor;
newColor=1.0-colorVarying; //1
gl_FragColor = texture2D( s_texture, v_texCoord )newColor; //2
}
Here in line 1, we’re merely taking the opposite of what was in the day-side shader. As
the color increases because of the sun, the dark-side texture fades to nothing. This
might be overkill, because the night-side texture would be washed out by the other, but
the lights are just a little too visible after the terminator for my taste.
There’s one final thing to do, and that is to modify your planet object so as to be
drawable with a vertex array object. Yes, it’s yet another interminable listing, as shown in
Listing 10-13. The data must first be packed into more efficient interleaved form,
referenced in Chapter 9. Afterward, a VAO is generated as a wrapper of sorts.
Listing 10-13. Creating a VAO for the Planet
-(void)createInterleavedData
{
int i;
GLfloat
vtxPtr;
GLfloat norPtr;
GLfloat
colPtr;
GLfloat textPtr;
int xyzSize;
int nxyzSize;
int rgbaSize;
int textSize;
struct VAOInterleaved
startData;
int structSize=sizeof(struct VAOInterleaved);
long allocSize=structSizem_NumVertices;
m_InterleavedData=(struct VAOInterleaved
)malloc(allocSize); //1
startData=m_InterleavedData;
vtxPtr=m_VertexData;
norPtr=m_NormalData;
colPtr=m_ColorData;
textPtr=m_TexCoordsData;
xyzSize=sizeof(GLfloat)NUM_XYZ_ELS;
nxyzSize=sizeof(GLfloat)
NUM_NXYZ_ELS;
rgbaSize=sizeof(GLfloat)NUM_RGBA_ELS;
textSize=sizeof(GLfloat)
NUM_ST_ELS;
for(i=0;i<m_NumVertices;i++) //2
{

Free download pdf