• In this lesson: – working with the camera Let’s recapitulate the material of the last lesson. 1) Our screen is two-dimensional. Accordingly, to display images, the system uses only the x and y coordinates. The z coordinate is used to determine which point to deduce if multiple points coincide with xy coordinates, and it does not add three-dimensionality. To give a three-dimensional image, w is used, with which the system emulates perspective. 2) In our application we want to describe the three-dimensional world and use the three-dimensional XYZ coordinate system for this purpose. 3) The perspective matrix allows us to implement the wish list of claim 2. It converts virtual…

• In this lesson: – use perspective mode– describe frustum– we use ortho-mode We turn to 3D. And first let’s figure out how we can realize the prospect. That is, as the distance from us, the objects become smaller, and as they approach – more. Download the source code and open the module lesson172_perspective. We look at the code, the class OpenGLRenderer. In the method prepareData two vertices are given. float x1 = -0.5f, y1 = -0.8f, x2 = 0.5f, y2 = -0.8f; float[] vertices = { x1, y1, 0.0f, 1.0f, x2, y2, 0.0f, 1.0f, }; Note that we use 4 values ​​for each vertex – x, y, z, and w.…

• In this lesson: – convey color for the vertices– use varying variable In the last lesson we learned how to draw graphic primitives. Now let’s learn to use different colors. Let me remind you that we set the color as follows: glUniform4f(uColorLocation, 0.0f, 0.0f, 1.0f, 1.0f); Where uColorLocation is a variable that knows where the u_Color variable responsible for color is located under the fragment shader (see Lesson 169). The glUniform4f method call can be taken from the bindData method and placed in the onDrawFrame We are opening a project with a lesson171_colors module in it. We look at the OpenGLRenderer class. It is similar to the same class in…

• In this lesson: – we draw graphic primitives The original lessons are available on githab. Download the project, we will use the lesson170_primitives module in it. In the last lesson, we learned how to transmit vertex data to shaders and obtain a triangle. To make this mechanism clearer, let’s try to develop a theme, and let’s create some examples of passing vertices and constructing different graphical primitives (point, line, and triangle) from these vertices. triangle Right now, our app draws one triangle. If we look at the OpenGLRenderer class, in the prepareData method we will see in it a list of vertices: float[] vertices = { -0.5f, -0.2f, 0.0f, 0.2f,…

• In this lesson: – we create shaders – draw a triangle The original lessons are available on githab. In the last lesson we created a simple project in which we simply painted the surface in green. At the same time we worked at the very top level and did not even touch the basic OpenGL mechanism, ie shaders. Shaders are programs written in GLSL. In 3D graphics, the entire image is constructed from graphic primitives: dots, lines, triangles. To draw a primitive, the GPU must know the coordinates of its vertices and the color of the fill for each point. This is what the shaders are giving him. And, accordingly,…

• In this lesson: – we create the simplest example from OpenGL We continue the topic of graphics, and move on to the next level, called OpenGL ES. It stands for OpenGL for Embedded Systems, ie OpenGL for Embedded Systems (android devices in our case). A couple of years ago, I read a book on the subject, made examples from it, and in general, without much difficulty, understood everything there was written. But the book was on OpenGL ES version 1.0. Now this version is already outdated and versions 2.0, 3.0 and 3.1 are used. These API versions are substantially different from and incompatible with 1.0. Therefore, I myself will have…

• In this lesson: – we use Canvas.saveLayer method In Lesson 146, we dealt with the save method. It can save the state of the canvas, perform various transformations and return to the saved state by the restore method. The saveLayer method creates a separate Bitmap canvas and forwards all subsequent canvas operations to it. And then to write the received result from Bitmap on an outline, it is necessary to call method restore. Those who have worked at least with graphic editors can draw an analogy with layers. You create a separate layer, draw something on it, then merge it with the main image. Actually, the method is called saveLayer…

• In this lesson: – create Drawable In the past lessons, we looked at some System Drawable ones, now I suggest you learn how to create them yourself. Drawable is an abstract class, and its heirs need to implement 4 of the following methods: 1) public abstract void draw (Canvas canvas) is probably the most important method, because here we are given a canvas and we need to draw on it what our custom Drawable should reflect 2) public abstract int getOpacity () – as far as I understand help, in this method we need to return the transparency value of our Drawable. There are 4 constants in total: UNKNOWN –…

• In this lesson: – We study Shader subclasses Using Shader class subclasses, we can draw. To do this, transfer the Shader object to the setShader brush method, and the brush will use a shader drawing to draw objects. Consider the existing heirs of the Shader class. I will do examples in Activity. All graphics will be implemented in the DrawView class. public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new DrawView(this)); } class DrawView extends View { public DrawView(Context context) { super(context); } @Override protected void onDraw(Canvas canvas) { canvas.drawARGB(80, 102, 204, 255); } } } BitmapShader To create this shader, you must pass it…

• In this lesson: – learn drawable tags: , , , , We continue to parse Drawable types that can be described using XML markup. We will not create any projects in this lesson. I’m just going to create XML files in a drawable folder in my project and set them as a background for View. And in the text of the lesson I will give the code and screens. Sometimes I will hang an extra gray background to see the actual size of the View. To programmatically get to Drawable, which you hung for View as a background, you just need to call the getBackground method. Level List tag allows…