protected String getFragmentShader() { return RawResourceReader.readTextFileFromRawResource(mContext, R.raw.per_pixel_fragment_shader); }
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { super.onSurfaceCreated(gl, config); // Set the background clear color to black. GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Use culling to remove back faces. GLES20.glEnable(GLES20.GL_CULL_FACE); // Enable depth testing GLES20.glEnable(GLES20.GL_DEPTH_TEST); // The below glEnable() call is a holdover from OpenGL ES 1, and is not needed in OpenGL ES 2. // Enable texture mapping // GLES20.glEnable(GLES20.GL_TEXTURE_2D); // Position the eye in front of the origin. final float eyeX = 0.0f; final float eyeY = 0.0f; final float eyeZ = -0.5f; // We are looking toward the distance final float lookX = 0.0f; final float lookY = 0.0f; final float lookZ = -5.0f; // Set our up vector. This is where our head would be pointing were we holding the camera. final float upX = 0.0f; final float upY = 1.0f; final float upZ = 0.0f; // Set the view matrix. This matrix can be said to represent the camera position. // NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and // view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose. Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); final String vertexShader = getVertexShader(); final String fragmentShader = getFragmentShader(); final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, vertexShader); final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader); mProgramHandle = ShaderHelper.createAndLinkProgram( vertexShaderHandle, fragmentShaderHandle, new String[] {"a_Position", "a_Color", "a_Normal", "a_TexCoordinate"}); // Define a simple shader program for our point. final String pointVertexShader = RawResourceReader.readTextFileFromRawResource(mContext, R.raw.point_vertex_shader); final String pointFragmentShader = RawResourceReader.readTextFileFromRawResource(mContext, R.raw.point_fragment_shader); final int pointVertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, pointVertexShader); final int pointFragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, pointFragmentShader); mPointProgramHandle = ShaderHelper.createAndLinkProgram( pointVertexShaderHandle, pointFragmentShaderHandle, new String[] {"a_Position"}); }
protected String getVertexShader() { return RawResourceReader.readTextFileFromRawResource(mContext, R.raw.per_pixel_vertex_shader); }