Game Development Reference
In-Depth Information
// Add the SpotLight Color for the mass
Color = Masses[i].GetGridSpotLightColor();
m_MassSpotLightColor[SpotLightLocationIndex] = Color[0];
m_MassSpotLightColor[SpotLightLocationIndex + 1] = Color[1];
m_MassSpotLightColor[SpotLightLocationIndex + 2] = Color[2];
SpotLightLocationIndex = SpotLightLocationIndex + 3;
MassesIndex++;
m_NumberMasses++;
}
return result;
}
The SetUpShader() function prepares the vertex shader to render the gravity grid.
The function does the following:
1.
Activates the shader
2.
Gets the position handle that serves to link the vertex position variable in the
shader to the main program that will send the vertex data to the shader
3.
Sets the specific values of the masses that are on the grid, such as the mass
value, radius of the spotlight, mass location, and the color of the spotlight
4.
Sets the color of the gravity grid in the shader
5.
Sets the value of the modelviewprojection matrix in the shader
See Listing 5-30 for the actual code details.
Listing 5-30. Setting Up the Vertex Shader for the Gravity Grid
void SetUpShader()
{
// Add program to OpenGL environment
m_Shader.ActivateShader();
// get handle to vertex shader's vPosition member
m_PositionHandle = m_Shader.GetShaderVertexAttributeVariableLocation("aPosition");
// Set Gravity Line Variables
m_Shader.SetShaderUniformVariableValueInt("NumberMasses", m_NumberMasses);
m_Shader.SetShaderVariableValueFloatVector1Array("MassValues", MAX_MASSES, m_MassValues, 0);
m_Shader.SetShaderVariableValueFloatVector3Array("MassLocations", MAX_MASSES,
m_MassLocations, 0);
m_Shader.SetShaderVariableValueFloatVector1Array("MassEffectiveRadius", MAX_MASSES,
m_MassEffectiveRadius, 0);
m_Shader.SetShaderVariableValueFloatVector3Array("SpotLightColor",MAX_MASSES,
m_MassSpotLightColor, 0);
Search WWH ::




Custom Search