Rendering our object on screen

In our previous chapter, we created a class for our Triangle object; however, if you run your game, it will still show a blank screen since we have not used our render class to display it. We need to create an object for our newly defined class, and then using our GL reference, we will draw/render it on our screen. Open up your MyGLRenderer.java file and let's start by declaring a variable of our triangle. We won't be altering any of our code that we wrote in onSurfaceCreated() or onSurfaceChanged() methods.

In order to draw our object on screen, we will simply follow these steps:

  1. Define a variable of our Triangle class.
  2. Assign a reference to it in our constructor.
  3. Using gl, access the draw() method in our ...

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.