use an ortho projection matrix to keep the quad square
This commit is contained in:
parent
63a9a5cd4b
commit
3450798278
@ -1,10 +1,11 @@
|
||||
|
||||
uniform mat4 projection;
|
||||
attribute vec3 pos;
|
||||
attribute vec3 color;
|
||||
varying vec3 color_i;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(pos * 0.75, 1);
|
||||
gl_Position = projection * vec4(pos * 0.75, 1);
|
||||
color_i = color;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user