use an ortho projection matrix to keep the quad square

This commit is contained in:
josh committed 2012-11-09 21:49:55 -05:00
1 parent 63a9a5cd4b
commit 3450798278
2 files changed
+22 -2

No files matched your search

@@ -14,6 +14,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
import android.opengl.Matrix;
public class MyRenderer implements GLSurfaceView.Renderer
{
@@ -21,6 +22,7 @@ public class MyRenderer implements GLSurfaceView.Renderer
private final String DBGTAG = "JoshsOpenGL";
private FloatBuffer m_quad_attrib_buffer;
private AssetManager m_asset_manager;
private float m_proj_matrix[] = new float[16];
public MyRenderer(AssetManager am)
{
@@ -113,7 +115,6 @@ public class MyRenderer implements GLSurfaceView.Renderer
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glUseProgram(m_program);
checkGLError("glBindBuffer");
int attr_pos = GLES20.glGetAttribLocation(m_program, "pos");
int attr_color = GLES20.glGetAttribLocation(m_program, "color");
@@ -137,5 +138,23 @@ public class MyRenderer implements GLSurfaceView.Renderer
public void onSurfaceChanged(GL10 unused, int width, int height)
{
GLES20.glViewport(0, 0, width, height);
if (width < height)
{
Matrix.orthoM(m_proj_matrix, 0, -1, 1,
-height / (float) width, height / (float) width, 1, -1);
}
else
{
Matrix.orthoM(m_proj_matrix, 0,
-width / (float) height, width / (float) height,
-1, 1, 1, -1);
}
GLES20.glUseProgram(m_program);
GLES20.glUniformMatrix4fv(
GLES20.glGetUniformLocation(m_program, "projection"),
1, false, m_proj_matrix, 0);
}
}