drawing one centered quad
This commit is contained in:
parent
e43f1bfa16
commit
a0bf1f8e4d
@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
varying vec2 tex_coord_i;
|
varying vec2 pos_2d_i;
|
||||||
uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D(tex, tex_coord_i);
|
gl_FragColor = vec4(0, 0.3, 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
|
|
||||||
uniform mat4 projection;
|
uniform mat4 projection;
|
||||||
uniform mat4 modelview;
|
uniform mat4 modelview;
|
||||||
attribute vec3 pos;
|
uniform vec2 offset;
|
||||||
attribute vec2 tex_coord;
|
|
||||||
varying vec2 tex_coord_i;
|
attribute vec2 pos;
|
||||||
|
|
||||||
|
varying vec2 pos_2d_i;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = projection * modelview * vec4(pos, 1);
|
gl_Position = projection *
|
||||||
tex_coord_i = tex_coord;
|
(modelview * vec4(pos, 0, 1) + vec4(offset, 0, 1));
|
||||||
|
pos_2d_i = pos + offset;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,9 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
private int m_width;
|
private int m_width;
|
||||||
private int m_height;
|
private int m_height;
|
||||||
private float m_aspect = 1.0f;
|
private float m_aspect = 1.0f;
|
||||||
private float m_x = 0.0f;
|
private final int GRID_WIDTH = 16;
|
||||||
private float m_y = 0.0f;
|
private final int GRID_HEIGHT = 9;
|
||||||
|
private float[][] m_tiles = new float[GRID_WIDTH][GRID_HEIGHT];
|
||||||
|
|
||||||
public MyRenderer(AssetManager am, Resources resources)
|
public MyRenderer(AssetManager am, Resources resources)
|
||||||
{
|
{
|
||||||
@ -93,10 +94,10 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
public void onSurfaceCreated(GL10 unused, EGLConfig config)
|
public void onSurfaceCreated(GL10 unused, EGLConfig config)
|
||||||
{
|
{
|
||||||
final float attribs[] = {
|
final float attribs[] = {
|
||||||
1, 1, 0, 1, 1,
|
1, 1,
|
||||||
-1, 1, 0, 0, 1,
|
-1, 1,
|
||||||
-1, -1, 0, 0, 0,
|
-1, -1,
|
||||||
1, -1, 0, 1, 0,
|
1, -1
|
||||||
};
|
};
|
||||||
checkGLError("onSurfaceCreated");
|
checkGLError("onSurfaceCreated");
|
||||||
ByteBuffer bb = ByteBuffer.allocateDirect(attribs.length * 4);
|
ByteBuffer bb = ByteBuffer.allocateDirect(attribs.length * 4);
|
||||||
@ -122,6 +123,7 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
Log.e(DBGTAG, "Program log: " + info_log);
|
Log.e(DBGTAG, "Program log: " + info_log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
Bitmap texture = BitmapFactory.decodeResource(m_resources,
|
Bitmap texture = BitmapFactory.decodeResource(m_resources,
|
||||||
R.drawable.texture);
|
R.drawable.texture);
|
||||||
int[] textures = new int[1];
|
int[] textures = new int[1];
|
||||||
@ -139,6 +141,7 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
|
GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
|
||||||
checkGLError("glGenerateMipmap");
|
checkGLError("glGenerateMipmap");
|
||||||
texture.recycle();
|
texture.recycle();
|
||||||
|
*/
|
||||||
|
|
||||||
GLES20.glClearColor(1.0f, 0.6f, 0.1f, 1.0f);
|
GLES20.glClearColor(1.0f, 0.6f, 0.1f, 1.0f);
|
||||||
}
|
}
|
||||||
@ -147,32 +150,22 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
{
|
{
|
||||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
long time = SystemClock.uptimeMillis() % 4000L;
|
|
||||||
float angle = 0.090f * ((int) time);
|
|
||||||
Matrix.setIdentityM(m_modelview, 0);
|
Matrix.setIdentityM(m_modelview, 0);
|
||||||
Matrix.translateM(m_modelview, 0, m_x, m_y, 0);
|
Matrix.translateM(m_modelview, 0, 0, 0, 0);
|
||||||
Matrix.rotateM(m_modelview, 0, angle, 0, 0, 1);
|
|
||||||
Matrix.scaleM(m_modelview, 0, 0.4f, 0.4f, 0.4f);
|
|
||||||
GLES20.glUniformMatrix4fv(
|
GLES20.glUniformMatrix4fv(
|
||||||
GLES20.glGetUniformLocation(m_program, "modelview"),
|
GLES20.glGetUniformLocation(m_program, "modelview"),
|
||||||
1, false, m_modelview, 0);
|
1, false, m_modelview, 0);
|
||||||
int attr_pos = GLES20.glGetAttribLocation(m_program, "pos");
|
int attr_pos = GLES20.glGetAttribLocation(m_program, "pos");
|
||||||
int attr_tex_coord = GLES20.glGetAttribLocation(m_program, "tex_coord");
|
|
||||||
checkGLError("glGetAttribLocation");
|
checkGLError("glGetAttribLocation");
|
||||||
GLES20.glEnableVertexAttribArray(attr_pos);
|
GLES20.glEnableVertexAttribArray(attr_pos);
|
||||||
GLES20.glEnableVertexAttribArray(attr_tex_coord);
|
|
||||||
checkGLError("glEnableVertexAttribArray");
|
checkGLError("glEnableVertexAttribArray");
|
||||||
m_quad_attrib_buffer.position(0);
|
m_quad_attrib_buffer.position(0);
|
||||||
GLES20.glVertexAttribPointer(attr_pos, 3, GLES20.GL_FLOAT, false,
|
GLES20.glVertexAttribPointer(attr_pos, 2, GLES20.GL_FLOAT, false,
|
||||||
5 * 4, m_quad_attrib_buffer);
|
2 * 4, m_quad_attrib_buffer);
|
||||||
m_quad_attrib_buffer.position(3);
|
|
||||||
GLES20.glVertexAttribPointer(attr_tex_coord, 2, GLES20.GL_FLOAT, false,
|
|
||||||
5 * 4, m_quad_attrib_buffer);
|
|
||||||
checkGLError("glVertexAttribPointer");
|
checkGLError("glVertexAttribPointer");
|
||||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);
|
GLES20.glDrawArrays(GLES20.GL_TRIANGLE_FAN, 0, 4);
|
||||||
checkGLError("glDrawArrays");
|
checkGLError("glDrawArrays");
|
||||||
GLES20.glDisableVertexAttribArray(attr_pos);
|
GLES20.glDisableVertexAttribArray(attr_pos);
|
||||||
GLES20.glDisableVertexAttribArray(attr_tex_coord);
|
|
||||||
checkGLError("glDisableVertexAttribArray");
|
checkGLError("glDisableVertexAttribArray");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,8 +178,9 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
GLES20.glViewport(0, 0, width, height);
|
GLES20.glViewport(0, 0, width, height);
|
||||||
|
|
||||||
Matrix.orthoM(m_proj_matrix, 0,
|
Matrix.orthoM(m_proj_matrix, 0,
|
||||||
-m_aspect, m_aspect,
|
-GRID_WIDTH / 2.0f, GRID_WIDTH / 2.0f,
|
||||||
-1, 1, 1, -1);
|
-GRID_HEIGHT / 2.0f, GRID_HEIGHT / 2.0f,
|
||||||
|
1, -1);
|
||||||
|
|
||||||
GLES20.glUseProgram(m_program);
|
GLES20.glUseProgram(m_program);
|
||||||
|
|
||||||
@ -200,12 +194,6 @@ public class MyRenderer implements GLSurfaceView.Renderer
|
|||||||
if (e.getAction() == MotionEvent.ACTION_DOWN ||
|
if (e.getAction() == MotionEvent.ACTION_DOWN ||
|
||||||
e.getAction() == MotionEvent.ACTION_MOVE)
|
e.getAction() == MotionEvent.ACTION_MOVE)
|
||||||
{
|
{
|
||||||
float x = m_aspect * ((e.getX() / (float) m_width) * 2.0f - 1.0f);
|
|
||||||
float y = -((e.getY() / (float) m_height) * 2.0f - 1.0f);
|
|
||||||
|
|
||||||
m_x = x;
|
|
||||||
m_y = y;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user