Graphics Reference
In-Depth Information
callback function, Draw , that will be called to render the frame. After exiting
esMain , the framework enters into the main loop, which will call the
registered callback functions ( Draw, Update ) until the window is closed.
Creating a Simple Vertex and Fragment Shader
In OpenGL ES 3.0, no geometry can be drawn unless a valid vertex
and fragment shader have been loaded. In Chapter 1, “Introduction
to OpenGL ES 3.0,” we covered the basics of the OpenGL ES 3.0
programmable pipeline. There, you learned about the concepts of
vertex and fragment shaders. These two shader programs describe the
transformation of vertices and drawing of fragments. To do any rendering
at all, an OpenGL ES 3.0 program must have at least one vertex shader
and one fragment shader.
The biggest task that the Init function in Hello Triangle accomplishes is
the loading of a vertex shader and a fragment shader. The vertex shader
that is given in the program is very simple:
char vShaderStr[] =
"#version 300 es \n"
"layout(location = 0) in vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"} \n";
The first line of the vertex shader declares the shader version that is being
used ( #version 300 es indicates OpenGL ES Shading Language v3.00).
The vertex shader declares one input attribute array—a four-component
vector named vPosition . Later on, the Draw function in Hello Triangle
will send in positions for each vertex that will be placed in this variable.
The layout(location = 0) qualifier signifies that the location of this
variable is vertex attribute 0. The shader declares a main function that
marks the beginning of execution of the shader. The body of the shader is
very simple; it copies the vPosition input attribute into a special output
variable named gl_Position . Every vertex shader must output a position
into the gl_Position variable. This variable defines the position that
is passed through to the next stage in the pipeline. The topic of writing
shaders is a large part of what we cover in this topic, but for now we just
want to give you a flavor of what a vertex shader looks like. In Chapter 5,
“OpenGL ES Shading Language,” we cover the OpenGL ES shading
 
 
Search WWH ::




Custom Search