Game Development Reference
In-Depth Information
function in the Renderer class. In our example from Chapter 3, that would be the MyGLRenderer
class. On Android, the exact statement to set the final viewport specifications is as follows:
GLES20. glViewport (0, 0, width, height);
The first two parameters specify the lower left coordinates of the viewport. The next two parameters
specify the width and the height of the viewport.
Sending the Matrices and Lighting Information to the Vertex and
Fragment Shaders
Next, you have to actually send the matrices to the vertex and fragment shaders that OpenGL ES 2.0
uses to render 3D objects.
Vertex shaders place the object's vertices into the 3D world using the model, view, and projection
matrix transforms that were mentioned in the preceding few sections. They also can determine the
diffuse and specular lighting at a vertex and pass this information along to the fragment shader.
Fragment or pixel shaders actually determine the final color at the vertex. In the fragment shader,
the texture, lighting, and material properties of the object all can provide input as to the final color.
The color of the entire object can then be interpolated from these vertex colors.
In our code framework, both vertex and fragment shaders are represented in the Shader class.
Within the Shader class, the GLES20.glUniformXXXX() series of functions actually are responsible for
sending the matrix, lighting, and material property data to the vertex and fragment shaders.
I discuss lighting and materials later in this chapter.
Rendering the Scene
Next, we have to actually render the scene. We render the scene in the onDrawFrame() function in our
Renderer class MyGLRenderer. The code statement that actually does the rendering is
m_Cube.DrawObject(m_Camera, m_PointLight);
DrawObject() is located in the Object3d class and takes two parameters as input: the camera and
the point light that is used to illuminate the scene.
Later in this chapter, I will go into more detail as to the OpenGL specific functions that draw an object.
Overview of the OpenGL ES 2.0 Shading Language
This section lists the basics of the shader language used for vertex and pixel shaders in OpenGL ES
2.0. It is not meant to be a full reference guide to every aspect of the language but a quick overview.
The purpose of this section is to familiarize you with the fundamentals of the language. If you wish to
learn more details about the shader language, see the web site at www.khronos.org/registry/gles/ .
 
Search WWH ::




Custom Search