DEV Community

Cover image for My notes on the OpenGL ES hello world triangle
Tristan Elliott
Tristan Elliott

Posted on • Edited on

My notes on the OpenGL ES hello world triangle

Table of contents

  1. What is this blog post?
  2. What is open gl es?
  3. What is a vertex?
  4. What is a vertex shader?
  5. What is a fragment?
  6. What is a fragment shader?
  7. Shader and Program objects

Resources

My app on the Google play store

What is this blog post?

What is open gl es?

  • As it open gl es is just a wrapper around open gl to make it more efficient for mobile/memory limited devices

What is a vertex?

  • A vertex is nothing more than a coordinate in a 2d or 3d space. So each point on a tringle is considered to be a vertex
  • In the open gl es triangle tutorial we create the vertices for the triangle in this array:
const GLfloat triangleVertices[] = {
        0.0f, 1.0f,   //x,y
        -1.0f, -1.0f, // x,y
        1.0f, -1.0f   // x,y
};

Enter fullscreen mode Exit fullscreen mode
  • Each of the x,y cordinates represent a vertex. So 0.0f, 1.0f is one vertex and so on

What is a vertex shader?

  • Documentation
  • programmable method for operating on vertices.
  • Below is just copy and pasted form the documentation
  • Vertex shaders are the most established and common kind of 3D shader and are run once for each vertex given to the graphics processor. The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen (as well as a depth value for the Z-buffer). Vertex shaders can manipulate properties such as position, color and texture coordinates, but cannot create new vertices. The output of the vertex shader goes to the next stage in the pipeline, which is either a geometry shader if present, or the rasterizer. Vertex shaders can enable powerful control over the details of position, movement, lighting, and color in any scene involving 3D models.

What is a fragment?

  • Graphics pipeline documentation
  • In the graphics pipeline there is a non-programmable(we can not touch it) step called Rasterization. Which turns our vertex data into points on the screen. Which it does by creating fragments, which is all the data necessary to generate a single pixel's worth of a drawing.

What is a fragment shader?

  • fragment shader documentation
  • The fragment shaders give us a programmable method to take the previously mentioned fragment data and alter the fragment data
  • The fragment shaders provides a general-purpose programmable method for operating on fragments.

Shaders and Programs

  • copy and pasted from OpenGL ES Programming guide
  • There are two fundamental object types needed to create to render with shaders

    • 1) Shader objects: The source code is given to the shader object and then the shader object is compiled into object form (like an .obj file). After compilation, the shader object can then be attached to a program object.
    • 2) Program objects: A program object gets multiple shader objects attached to it. In OpenGL ES, each program object will need to have one vertex shader object and one fragment shader object attached to it (no more, and no less). The program object is then linked into a final “executable.” The final program object can then be used to render.

Conclusion

  • Thank you for taking the time out of your day to read this blog post of mine. If you have any questions or concerns please comment below or reach out to me on Twitter.

Top comments (0)