title: Android Changing OpenGL Coordinate System
body: <p>Ok so I found this <a href="https://stackoverflow.com/questions/5814374/blank-screen-when-using-gluortho2d">thread</a>, which is what I believe I need to do. However, I am not using <code>GL10</code> but <code>GLES20</code>. <code>glOrthof</code> isn't a part of the <code>GLES20</code> API.</p>
  
  <p>What I want to do is <strong>change the coordinate system's</strong> range from [-1, 1] <strong>to</strong> <strong>[0,1]</strong>.
  This is the normal system.</p>
  
  <p><a href="https://i.stack.imgur.com/rKncC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rKncC.png" alt="Normal Coord System"></a></p>
  
  <p><strong>I would like to change it so that it is this.(Below)</strong> </p>
  
  <p><a href="https://i.stack.imgur.com/X6r8k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X6r8k.png" alt="enter image description here"></a></p>
  
  <p><strong>The center of the screen is 0.5f, 0.5f, bottom left is 0f,0f, etc.</strong> It is only 2D.</p>
  
  <pre><code>private final String vertexShaderCode = 
      "uniform mat4 uMVPMatrix;" +  
      "attribute vec4 aPosition;" +   
      "attribute vec2 aTexCoordinate;" +  
      "varying vec2 vTexCoordinate;" +
      "void main() {" +
      "  gl_Position = uMVPMatrix * aPosition;" +
      "  vTexCoordinate = aTexCoordinate;" +
      "}";
  </code></pre>
  
  <p><strong>Here is my Renderer class</strong></p>
  
  <pre><code>import javax.microedition.khronos.egl.EGLConfig;
  import javax.microedition.khronos.opengles.GL10;
  import android.opengl.GLES20;
  import android.opengl.GLSurfaceView;
  import android.opengl.Matrix;
  import android.util.Log;
  
  import com.matt.world.World;
  
  
  public class OpenGLRenderer implements GLSurfaceView.Renderer {
  
      private static final String TAG = "OpenGLRenderer";             // Tag for the logcat error message
  
      private final float[] mMVPMatrix = new float[16];               // mMVPMatrix is an abbreviation for "Model View Projection Matrix"
      private final float[] mProjectionMatrix = new float[16];
      private final float[] mViewMatrix = new float[16];
      private final float[] mRotationMatrix = new float[16];
      private final float[] mTranslationMatrix = new float[16];
  
      private World mWorld;                                           // World object
      private long mStartTime;                                        // Start time
  
      public volatile float mPlayerInputX;                            // Variable to receive player coordinate input
      public volatile float mPlayerInputY;                            // Variable to receive player coordinate input
      public volatile boolean mFireWeapon = false;                    // Variable to handle player fire commands
      public volatile boolean mToggleShield = false;                  // Variable to handle player shield toggle
      public volatile boolean mToggleLaser = false;                   // Variable to handle player laser toggle
  
      @Override
      public void onSurfaceCreated(GL10 unused, EGLConfig config) {   // Called once when the surface is created
  
          GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);                // Set the background frame color
          GLES20.glEnable(GLES20.GL_TEXTURE_2D);                      // Enable textures
          mWorld = new World(this);                                   // Initialize World object
      }
  
      @Override
      public void onDrawFrame(GL10 unused) {                          // Called every frame
          float[] scratch = new float[16];                            // Container for matrix manipulations
          float decimal = 1000000000.0f;                              // Divisor to move the decimal point for delta time
  
          GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT |                 // Draw background color
                  GLES20.GL_DEPTH_BUFFER_BIT);
  
          Matrix.setLookAtM(mViewMatrix,                              // Set the camera position (View matrix)
                  0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  
          Matrix.multiplyMM(mMVPMatrix,                               // Calculate the projection and view transformation
                  0, mProjectionMatrix, 0, mViewMatrix, 0);
  
          float deltaTime = (System.nanoTime()-mStartTime)/decimal;   // Calculate delta time
          mStartTime = System.nanoTime();                             // Get the time now for next frame calculations
          mWorld.update(mMVPMatrix, deltaTime);                       // Update World
          mWorld.draw();                                              // Draw World
      }
  
      @Override
      public void onSurfaceChanged(GL10 unused, int width, int height) {
  
          GLES20.glViewport(0,0, width, height);                       // Adjust the viewport based on geometry changes,
  
  
          float ratio = (float) height / width;                       // such as screen rotation
  
          Matrix.setIdentityM(mProjectionMatrix, 0);                  // Set this matrix to the identity matrix
  
          Matrix.frustumM(mProjectionMatrix,                          // this projection matrix is applied to object coordinates
                  0,-ratio, ratio, 0, 1, 3, 7);                       // in the onDrawFrame() method*/
  
          mStartTime = System.nanoTime();                             // keep record of what the current time is
      }
  
      public static int loadShader(int type, String shaderCode){
          int shader = GLES20.glCreateShader(type);                   // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
                                                                      // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
          GLES20.glShaderSource(shader, shaderCode);                  // add the source code to the shader and
          GLES20.glCompileShader(shader);                             // compile it
          return shader;
      }
  
      public static void checkGlError(String glOperation) {
          int error;
          while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
              Log.e(TAG, glOperation + ": glError " + error);
              throw new RuntimeException(glOperation + ": glError " + error);
          }
      }
  
  }
  </code></pre>