In the following screenshot, the two squares have a common area and their colors are mixed. In our case, the RGBA components of the green square are multiplied by 1 and added to the RGBA components of the red square multiplied by 1.
In the “onSurfaceCreated()” method is enabled the use of textures and the textures are loaded with the “LoadTexture()” method. With “DrawTexture()” we draw the square specifying which texture to use through an index that coincides with the loading order.
Every shape we want to draw must be brought back into triangles, therefore OpenGL will draw the square with 2 triangles. The “indices” variable specifies the vertices to be taken from “vertices” for each triangle (counterclockwise). For the first triangle, pair of coordinates x,y: 0, 1 and 2, for the second triangle, pair of coordinates x,y: 2, 1 and 3.
In this tutorial we set the colors of the vertices individually.
In the first code, for each triangle, we reset, translate, scale and draw. In the second code, we reset, scale (obtaining a basic unit of “100”), translate by 1 (that is 100), draw, translate again by 1 (that is an other 100) on the previous translate, draw.
With “this.objtriangle = new ObjTriangle();” we call the constructor of “ObjTriangle” class where we set the data of our triangle. The vertices of the triangle present in “vertices” and “indices” (written counterclockwise) are not in a format useful for OpenGL, in the constructor they are converted and stored in “vertexBuffer” and “indexBuffer”.
OpenGL for Embedded Systems (OpenGL ES or GLES) is a subset of the OpenGL computer graphics rendering application programming interface (API) for rendering 2D and 3D computer graphics such as those used by video games, typically hardware-accelerated using a graphics processing unit (GPU). It is designed for embedded systems like smartphones, tablet computers, video game consoles and PDAs.