revert to regular shader

This commit is contained in:
Josh Holtrop 2012-12-01 08:10:13 -05:00
parent 490f8973d2
commit 2ddae706eb
3 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
varying vec2 pos_2d_i; varying vec3 color_i;
void main() void main()
{ {
gl_FragColor = vec4(0, 0.3, 1, 1); gl_FragColor = vec4(color_i, 1);
} }

View File

@ -4,12 +4,12 @@ uniform mat4 modelview;
uniform vec2 offset; uniform vec2 offset;
attribute vec2 pos; attribute vec2 pos;
attribute vec3 color;
varying vec2 pos_2d_i; varying vec3 color_i;
void main() void main()
{ {
gl_Position = projection * gl_Position = projection * modelview * vec4(pos, 0, 1);
(modelview * vec4(pos, 0, 1) + vec4(offset, 0, 0)); color_i = color;
pos_2d_i = pos + offset;
} }

View File

@ -93,10 +93,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, 1, 1, 0.8f, 0.8f, 1,
0, 1, 0, 1, 0, 0, 1,
0, 0, 0, 0, 0.8f, 0.8f, 1,
1, 0 1, 0, 0, 0, 1
}; };
checkGLError("onSurfaceCreated"); checkGLError("onSurfaceCreated");
ByteBuffer bb = ByteBuffer.allocateDirect(attribs.length * 4); ByteBuffer bb = ByteBuffer.allocateDirect(attribs.length * 4);
@ -150,13 +150,19 @@ public class MyRenderer implements GLSurfaceView.Renderer
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
int attr_pos = GLES20.glGetAttribLocation(m_program, "pos"); int attr_pos = GLES20.glGetAttribLocation(m_program, "pos");
int attr_color = GLES20.glGetAttribLocation(m_program, "color");
checkGLError("glGetAttribLocation"); checkGLError("glGetAttribLocation");
GLES20.glEnableVertexAttribArray(attr_pos); GLES20.glEnableVertexAttribArray(attr_pos);
GLES20.glEnableVertexAttribArray(attr_color);
checkGLError("glEnableVertexAttribArray"); checkGLError("glEnableVertexAttribArray");
m_quad_attrib_buffer.position(0);
GLES20.glVertexAttribPointer(attr_pos, 2, GLES20.GL_FLOAT, false, GLES20.glVertexAttribPointer(attr_pos, 2, GLES20.GL_FLOAT, false,
2 * 4, m_quad_attrib_buffer); 5 * 4, m_quad_attrib_buffer);
m_quad_attrib_buffer.position(2);
GLES20.glVertexAttribPointer(attr_color, 3, GLES20.GL_FLOAT, false,
5 * 4, m_quad_attrib_buffer);
checkGLError("glVertexAttribPointer"); checkGLError("glVertexAttribPointer");
for (int y = 0; y < GRID_HEIGHT; y++) for (int y = 0; y < GRID_HEIGHT; y++)
@ -166,18 +172,17 @@ public class MyRenderer implements GLSurfaceView.Renderer
Matrix.setIdentityM(m_modelview, 0); Matrix.setIdentityM(m_modelview, 0);
Matrix.translateM(m_modelview, 0, Matrix.translateM(m_modelview, 0,
x - GRID_WIDTH / 2.0f, y - GRID_HEIGHT / 2.0f, 0); x - GRID_WIDTH / 2.0f, y - GRID_HEIGHT / 2.0f, 0);
Matrix.scaleM(m_modelview, 0, 0.9f, 0.9f, 0.9f);
GLES20.glUniformMatrix4fv( GLES20.glUniformMatrix4fv(
GLES20.glGetUniformLocation(m_program, "modelview"), GLES20.glGetUniformLocation(m_program, "modelview"),
1, false, m_modelview, 0); 1, false, m_modelview, 0);
m_quad_attrib_buffer.position(0);
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_color);
checkGLError("glDisableVertexAttribArray"); checkGLError("glDisableVertexAttribArray");
} }