public Desktop(Display display) { mDisplay = display; mVertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER); mFragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER); mProgramHandle = ShaderHelper.createAndLinkProgram( mVertexShaderHandle, mFragmentShaderHandle, new String[] {"a_Position", "a_TexCoordinate", "u_CombinedMatrix", "u_Texture"}); mCombinedMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_CombinedMatrix"); mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture"); mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position"); mTransparentHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_transparency"); mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate"); mTextureDataHandle = TextureHelper.createTextureHandle(); }
public Points() { mRGB[0] = 0.8f; mRGB[1] = 0.2f; mRGB[2] = 0.2f; // prepare shaders and OpenGL program int vertexShader = ShaderHelper.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); int fragmentShader = ShaderHelper.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode); mProgram = ShaderHelper.createAndLinkProgram(vertexShader, fragmentShader); mPosition = GLES20.glGetAttribLocation(mProgram, "vPosition"); mColor = GLES20.glGetAttribLocation(mProgram, "vColor"); mMVPMatrix = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); initSomePoints(); loadVBO(); mMediumPointThread = new MediumPoint(); mMediumPointThread.start(); enable(); Log.d(TAG, "Rendered points = " + totalPoints); }
@Override public void init(Context context, AttributeSet attrs, int defStyle) { super.init(context, attrs, defStyle); borderWidth = 0; if (attrs != null) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ShaderImageView, defStyle, 0); triangleHeightPx = typedArray.getDimensionPixelSize(R.styleable.ShaderImageView_siTriangleHeight, 0); int arrowPositionInt = typedArray.getInt( R.styleable.ShaderImageView_siArrowPosition, ArrowPosition.LEFT.ordinal()); arrowPosition = ArrowPosition.values()[arrowPositionInt]; typedArray.recycle(); } if (triangleHeightPx == 0) { triangleHeightPx = dpToPx(context.getResources().getDisplayMetrics(), DEFAULT_HEIGHT_DP); } }
protected ShaderProgram(String vertexShader, String fragmentShader) { program = ShaderHelper.build(vertexShader, fragmentShader); }
@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"}); }