Java Code Examples for android.opengl.GLES20

The following are top voted examples for showing how to use android.opengl.GLES20. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: UNIST-pixel-dungeon   File: NoosaScript.java   Source Code and License 6 votes vote down vote up
public void drawQuadSet( Vertexbuffer buffer, int length, int offset ){

		if (length == 0) {
			return;
		}

		buffer.updateGLData();

		buffer.bind();

		aXY.vertexBuffer( 2, 4, 0 );
		aUV.vertexBuffer( 2, 4, 2 );

		buffer.release();

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
			GLES20.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * length, GLES20.GL_UNSIGNED_SHORT, Quad.SIZE * Short.SIZE/8 * offset );
		} else {
			FroyoGLES20Fix.glDrawElements( GLES20.GL_TRIANGLES, Quad.SIZE * length, GLES20.GL_UNSIGNED_SHORT, Quad.SIZE * Short.SIZE/8 * offset );
		}
	}
 
Example 2
Project: ParsingPlayer   File: VideoRenderThread.java   Source Code and License 6 votes vote down vote up
private int createShader(int shaderType, String shaderString) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader == 0) {
        checkGLESError("create shader " + shaderType);
    }

    GLES20.glShaderSource(shader, shaderString);
    GLES20.glCompileShader(shader);
    int[] compiled = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
    if (compiled[0] == 0) {
        GLES20.glDeleteShader(shader);
        checkGLESError("compile shader " + shaderType);
    }
    return shader;
}
 
Example 3
Project: VideoCRE   File: YuvConverter.java   Source Code and License 6 votes vote down vote up
/**
 * This class should be constructed on a thread that has an active EGL context.
 */
public YuvConverter() {
  threadChecker.checkIsOnValidThread();
  textureFrameBuffer = new GlTextureFrameBuffer(GLES20.GL_RGBA);
  shader = new GlShader(VERTEX_SHADER, FRAGMENT_SHADER);
  shader.useProgram();
  texMatrixLoc = shader.getUniformLocation("texMatrix");
  xUnitLoc = shader.getUniformLocation("xUnit");
  coeffsLoc = shader.getUniformLocation("coeffs");
  GLES20.glUniform1i(shader.getUniformLocation("oesTex"), 0);
  GlUtil.checkNoGLES2Error("Initialize fragment shader uniform values.");
  // Initialize vertex shader attributes.
  shader.setVertexAttribArray("in_pos", 2, DEVICE_RECTANGLE);
  // If the width is not a multiple of 4 pixels, the texture
  // will be scaled up slightly and clipped at the right border.
  shader.setVertexAttribArray("in_tc", 2, TEXTURE_RECTANGLE);
}
 
Example 4
Project: Android_OpenGL_Demo   File: LessonSixRenderer.java   Source Code and License 6 votes vote down vote up
private void drawLight() {
    final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
    final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");

    // Pass in the position.
    GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);

    // Since we are not using a buffer object, disable vertex arrays for this attribute.
    GLES20.glDisableVertexAttribArray(pointPositionHandle);

    // Pass in the transformation matrix.
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // Draw the point.
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
 
Example 5
Project: AndroidRTC   File: GlShader.java   Source Code and License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
  final int shader = GLES20.glCreateShader(shaderType);
  if (shader == 0) {
    throw new RuntimeException("glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compileStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
  if (compileStatus[0] != GLES20.GL_TRUE) {
    Logging.e(
        TAG, "Could not compile shader " + shaderType + ":" + GLES20.glGetShaderInfoLog(shader));
    throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
  }
  GlUtil.checkNoGLES2Error("compileShader");
  return shader;
}
 
Example 6
Project: android-magic-surface-view   File: GLUniformParameter.java   Source Code and License 6 votes vote down vote up
private void updateFloatValue(float... value) {
    switch (value.length) {
        case 1:
            GLES20.glUniform1f(handle(), value[0]);
            break;
        case 2:
            GLES20.glUniform2f(handle(), value[0], value[1]);
            break;
        case 3:
            GLES20.glUniform3f(handle(), value[0], value[1], value[2]);
            break;
        case 4:
            GLES20.glUniform4f(handle(), value[0], value[1], value[2], value[3]);
            break;
        case 16:
            GLES20.glUniformMatrix4fv(handle(), 1, false, value, 0);
        default:
            break;
    }
}
 
Example 7
Project: GLhexagram   File: Hexagram.java   Source Code and License 6 votes vote down vote up
/**
 * 初始化着色器
 * @param surfaceView
 */
private void initShader(HexagramSurfaceView surfaceView) {
    //加载顶点着色器
    mVertexShader = ShaderUtil.loadFromAeertsFile("vertex.sh" , surfaceView.getResources());
    //加载片元着色器
    mFragmentShader = ShaderUtil.loadFromAeertsFile("frag.sh" , surfaceView.getResources());
    //创建程序
    mProgram = ShaderUtil.createProgram(mVertexShader , mFragmentShader);
    //顶点位置属性引用
    maPositionHandle = GLES20.glGetAttribLocation(mProgram , "aPosition");
    //顶点颜色属性引用
    maColorHandle = GLES20.glGetAttribLocation(mProgram , "aColor");
    //总变换矩阵引用
    muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram , "uMVPMatrix");

}
 
Example 8
Project: aos-Video   File: StereoDiveEffect.java   Source Code and License 6 votes vote down vote up
private void setupPreScene(int glProgram) {
    GLES20.glUseProgram(glProgram);
    mTexHandle = GLES20.glGetUniformLocation(glProgram, "s_texture");
    mTexCoordHandle = GLES20.glGetAttribLocation(glProgram, "a_texCoord");
    mTriangleVerticesHandle = GLES20.glGetAttribLocation(glProgram, "vPosition");
    mTransformHandle = GLES20.glGetUniformLocation(glProgram, "u_xform");
    mMVPTransformHandle = GLES20.glGetUniformLocation(glProgram, "u_mvp_xform");
    if (CHECK_GL_ERRORS) OpenGLUtils.checkGlError("glUseProgram");

    GLES20.glUniformMatrix4fv(mTransformHandle, 1, false, mVideoTransform, 0);
    if (CHECK_GL_ERRORS) OpenGLUtils.checkGlError("glUniformMatrix4fv");

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    
    mColorFilterHandle = GLES20.glGetUniformLocation(glProgram, "u_filter");
    mColorFilter = CLEAR_COLOR_FILTER;
}
 
Example 9
Project: ESPD   File: Game.java   Source Code and License 6 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {

	if (width == 0 || height == 0) {
		return;
	}

	SystemTime.tick();
	long rightNow = SystemClock.elapsedRealtime();
	step = (now == 0 ? 0 : rightNow - now);
	now = rightNow;

	step();

	NoosaScript.get().resetCamera();
	NoosaScriptNoLighting.get().resetCamera();
	GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
	GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
	draw();
}
 
Example 10
Project: Android_OpenGL_Demo   File: LessonTwoRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Draws a point representing the position of the light.
 */
private void drawLight()
{
	final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
       final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");

	// Pass in the position.
	GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);

	// Since we are not using a buffer object, disable vertex arrays for this attribute.
       GLES20.glDisableVertexAttribArray(pointPositionHandle);

	// Pass in the transformation matrix.
	Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
	Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
	GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);

	// Draw the point.
	GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
}
 
Example 11
Project: AAVT   File: FluorescenceFilter.java   Source Code and License 6 votes vote down vote up
@Override
protected void onSetExpandData() {
    //todo 根据时间修改

    if(isAdd){
        mStep+=0.08f;
    }else{
        mStep-=0.08f;
    }

    if(mStep>=1.0f){
        isAdd=false;
        mStep=1.0f;
    }else if(mStep<=0.0f){
        isAdd=true;
        mStep=0.0f;
    }

    super.onSetExpandData();
    GLES20.glUniform4fv(mGLBorderColor,1,mBorderColor,0);
    GLES20.glUniform1f(mGLStep,mStep);
}
 
Example 12
Project: alpha-movie   File: VideoRenderer.java   Source Code and License 6 votes vote down vote up
private int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        GLES20.glShaderSource(shader, source);
        GLES20.glCompileShader(shader);
        int[] compiled = new int[1];
        GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
        if (compiled[0] == 0) {
            Log.e(TAG, "Could not compile shader " + shaderType + ":");
            Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
            GLES20.glDeleteShader(shader);
            shader = 0;
        }
    }
    return shader;
}
 
Example 13
Project: grafika   File: HardwareScalerActivity.java   Source Code and License 6 votes vote down vote up
/**
 * Prepares window surface and GL state.
 */
private void prepareGl(Surface surface) {
    Log.d(TAG, "prepareGl");

    mWindowSurface = new WindowSurface(mEglCore, surface, false);
    mWindowSurface.makeCurrent();

    // Programs used for drawing onto the screen.
    mFlatProgram = new FlatShadedProgram();
    mTexProgram = new Texture2dProgram(Texture2dProgram.ProgramType.TEXTURE_2D);
    mCoarseTexture = GeneratedTexture.createTestTexture(GeneratedTexture.Image.COARSE);
    mFineTexture = GeneratedTexture.createTestTexture(GeneratedTexture.Image.FINE);

    // Set the background color.
    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    // Disable depth testing -- we're 2D only.
    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    // Don't need backface culling.  (If you're feeling pedantic, you can turn it on to
    // make sure we're defining our shapes correctly.)
    GLES20.glDisable(GLES20.GL_CULL_FACE);
}
 
Example 14
Project: PaoMovie   File: OpenGLUtils.java   Source Code and License 6 votes vote down vote up
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId,final int type) {
if(data == null)
	return NO_TEXTURE;
   int textures[] = new int[1];
   if (usedTexId == NO_TEXTURE) {
       GLES20.glGenTextures(1, textures, 0);
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
               GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
       GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height,
               0, GLES20.GL_RGBA, type, data);
   } else {
       GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
       GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, width,
               height, GLES20.GL_RGBA, type, data);
       textures[0] = usedTexId;
   }
   return textures[0];
  }
 
Example 15
Project: airgram   File: PhotoFilterView.java   Source Code and License 6 votes vote down vote up
public Bitmap getTexture() {
    if (!initied) {
        return null;
    }
    final Semaphore semaphore = new Semaphore(0);
    final Bitmap object[] = new Bitmap[1];
    try {
        postRunnable(new Runnable() {
            @Override
            public void run() {
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderFrameBuffer[1]);
                GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTexture[blured ? 0 : 1], 0);
                GLES20.glClear(0);
                object[0] = getRenderBufferBitmap();
                semaphore.release();
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
                GLES20.glClear(0);
            }
        });
        semaphore.acquire();
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return object[0];
}
 
Example 16
Project: poly-sample-android   File: PointCloudRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Updates the OpenGL buffer contents to the provided point.  Repeated calls with the same
 * point cloud will be ignored.
 */
public void update(PointCloud cloud) {
    if (mLastPointCloud == cloud) {
        // Redundant call.
        return;
    }

    ShaderUtil.checkGLError(TAG, "before update");

    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mVbo);
    mLastPointCloud = cloud;

    // If the VBO is not large enough to fit the new point cloud, resize it.
    mNumPoints = mLastPointCloud.getPoints().remaining() / FLOATS_PER_POINT;
    if (mNumPoints * BYTES_PER_POINT > mVboSize) {
        while (mNumPoints * BYTES_PER_POINT > mVboSize) {
            mVboSize *= 2;
        }
        GLES20.glBufferData(GLES20.GL_ARRAY_BUFFER, mVboSize, null, GLES20.GL_DYNAMIC_DRAW);
    }
    GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, mNumPoints * BYTES_PER_POINT,
        mLastPointCloud.getPoints());
    GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);

    ShaderUtil.checkGLError(TAG, "after update");
}
 
Example 17
Project: EZFilter   File: CameraInput.java   Source Code and License 6 votes vote down vote up
@Override
protected void bindShaderValues() {
    mRenderVertices.position(0);
    GLES20.glVertexAttribPointer(mPositionHandle, 2, GLES20.GL_FLOAT, false,
            8, mRenderVertices);
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    mTextureVertices[mCurrentRotation].position(0);
    GLES20.glVertexAttribPointer(mTextureCoordHandle, 2, GLES20.GL_FLOAT, false,
            8, mTextureVertices[mCurrentRotation]);
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureIn);
    GLES20.glUniform1i(mTextureHandle, 0);

    mSurfaceTexture.getTransformMatrix(mMatrix);
    GLES20.glUniformMatrix4fv(mMatrixHandle, 1, false, mMatrix, 0);
}
 
Example 18
Project: mao-android   File: BaseCameraView.java   Source Code and License 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    mLog.i("onSurfaceChanged");
    GLES20.glViewport(0, 0, width, height);
    mSurfaceWidth = width;
    mSurfaceHeight = height;
    mCameraFilterGroup.initFrameBuffer(width, height);
}
 
Example 19
Project: MediaCodecRecorder   File: GLUtil.java   Source Code and License 5 votes vote down vote up
public static int loadProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (fragmentShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    GLES20.glAttachShader(program, fragmentShader);
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }

    GLES20.glDeleteShader(vertexShader);
    GLES20.glDeleteShader(fragmentShader);
    return program;
}
 
Example 20
Project: VideoCompressor   File: TextureRenderer.java   Source Code and License 5 votes vote down vote up
public void drawFrame(SurfaceTexture st, boolean invert) {
    checkGlError("onDrawFrame start");
    st.getTransformMatrix(mSTMatrix);

    if (invert) {
        mSTMatrix[5] = -mSTMatrix[5];
        mSTMatrix[13] = 1.0f - mSTMatrix[13];
    }

    GLES20.glUseProgram(mProgram);
    checkGlError("glUseProgram");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
    GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maPosition");
    GLES20.glEnableVertexAttribArray(maPositionHandle);
    checkGlError("glEnableVertexAttribArray maPositionHandle");
    mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
    GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
    checkGlError("glVertexAttribPointer maTextureHandle");
    GLES20.glEnableVertexAttribArray(maTextureHandle);
    checkGlError("glEnableVertexAttribArray maTextureHandle");
    GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
    GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    checkGlError("glDrawArrays");
    GLES20.glFinish();
}
 
Example 21
Project: mao-android   File: EglSurfaceBase.java   Source Code and License 5 votes vote down vote up
public Bitmap getFrameBitmap() {
    if (!mEglCore.isCurrent(mEGLSurface)) {
        throw new RuntimeException("Expected EGL context/surface is not current");
    }

    // glReadPixels fills in a "direct" ByteBuffer with what is essentially big-endian RGBA
    // data (i.e. a byte of red, followed by a byte of green...).  While the Bitmap
    // constructor that takes an int[] wants little-endian ARGB (blue/red swapped), the
    // Bitmap "copy pixels" method wants the same format GL provides.
    //
    // Ideally we'd have some way to re-use the ByteBuffer, especially if we're calling
    // here often.
    //
    // Making this even more interesting is the upside-down nature of GL, which means
    // our output will look upside down relative to what appears on screen if the
    // typical GL conventions are used.

    int width = getWidth();
    int height = getHeight();
    ByteBuffer buf = ByteBuffer.allocateDirect(width * height * 4);
    buf.order(ByteOrder.LITTLE_ENDIAN);
    GLES20.glReadPixels(0, 0, width, height,
            GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buf);
    //GlUtil.checkGlError("glReadPixels");
    buf.rewind();

    Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    bmp.copyPixelsFromBuffer(buf);

    Matrix matrix = new Matrix();
    matrix.preScale(1f, -1f);
    Bitmap bmp2 = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, false);

    bmp.recycle();
    bmp = null;
    return bmp2;
}
 
Example 22
Project: MOAAP   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}
 
Example 23
Project: buildAPKsApps   File: GLLayer.java   Source Code and License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 glUnused) {
	GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
	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_TexCoordinate" });

	// Set our per-vertex lighting program.
	GLES20.glUseProgram(mProgramHandle);

	// Set program handles for cube drawing.
	mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle,
			"u_MVPMatrix");
	mTextureUniformHandle0 = GLES20.glGetUniformLocation(mProgramHandle,
			"u_Texture0");
	mTextureUniformHandle1 = GLES20.glGetUniformLocation(mProgramHandle,
			"u_Texture1");
	mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle,
			"a_Position");
	mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle,
			"a_TexCoordinate");

	/**
	 * First texture map
	 */
	// Set the active texture0 unit to texture unit 0.
	GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

	// Bind the texture to this unit.
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle0);

	// Tell the texture uniform sampler to use this texture in the shader by
	// binding to texture unit 0.
	GLES20.glUniform1i(mTextureUniformHandle0, 0);
	
	/**
	 * Second texture map
	 */
	// Set the active texture1 unit to texture unit 1.
	GLES20.glActiveTexture(GLES20.GL_TEXTURE1);

	// Bind the texture to this unit.
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle1);

	// Tell the texture uniform sampler to use this texture in the shader by
	// binding to texture unit 1.
	GLES20.glUniform1i(mTextureUniformHandle1, 1);

	// Draw some cubes.
	Matrix.setIdentityM(mModelMatrix, 0);
	Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.2f);
	Matrix.rotateM(mModelMatrix, 0, 0.0f, 1.0f, 1.0f, 0.0f);
	drawCube();
}
 
Example 24
Project: Building-Android-UIs-with-Custom-Views   File: GLDrawer.java   Source Code and License 5 votes vote down vote up
private void initShaders() {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    shaderProgram = GLES20.glCreateProgram();
    GLES20.glAttachShader(shaderProgram, vertexShader);
    GLES20.glAttachShader(shaderProgram, fragmentShader);
    GLES20.glLinkProgram(shaderProgram);
}
 
Example 25
Project: Zero   File: GLLayer.java   Source Code and License 5 votes vote down vote up
void draw(int texture, float[] mvpMatrix) {
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glUseProgram(program);

    GLES20.glEnable(GLES20.GL_BLEND);

    // Note: android uses premultiplied alpha for bitmaps!
    GLES20.glBlendFunc(GLES20.GL_ONE, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    int positionHandle = GLES20.glGetAttribLocation(program, "aPosition");
    int textureHandle = GLES20.glGetUniformLocation(program, "uTexture");
    int texturePositionHandle = GLES20.glGetAttribLocation(program, "aTexPosition");
    int MVPMatrixHandle = GLES20.glGetUniformLocation(program, "uMVPMatrix");

    GLES20.glVertexAttribPointer(texturePositionHandle, 2, GLES20.GL_FLOAT, false, 0, textureBuffer);
    GLES20.glEnableVertexAttribArray(texturePositionHandle);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture);
    GLES20.glUniform1i(textureHandle, 0);

    GLES20.glVertexAttribPointer(positionHandle, 2, GLES20.GL_FLOAT, false, 0, verticesBuffer);
    GLES20.glEnableVertexAttribArray(positionHandle);

    GLES20.glUniformMatrix4fv(MVPMatrixHandle, 1, false, mvpMatrix, 0);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);

    GLES20.glDisable(GLES20.GL_BLEND);
}
 
Example 26
Project: PaoMovie   File: MagiSkinWhitenFilter.java   Source Code and License 5 votes vote down vote up
public void onInitialized() {
    super.onInitialized();
    runOnDraw(new Runnable() {
        
        public void run() {		        
      GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
   GLES20.glGenTextures(1, mToneCurveTexture, 0);
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
   GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
              GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
              GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
              GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
              GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);		        
      byte[] arrayOfByte = new byte[1024];
      int[] arrayOfInt1 = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
      int[] arrayOfInt2 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 };
      for (int i = 0; i < 256; i++){
        arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]);
        arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]);
        arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt2[i]);
        arrayOfByte[(3 + i * 4)] = -1;
      }
            GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte));
        }
    });
}
 
Example 27
Project: PaoMovie   File: MagicSutroFilter.java   Source Code and License 5 votes vote down vote up
protected void onDrawArraysAfter(){
	for(int i = 0; i < inputTextureHandles.length
			&& inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3));
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
	}
}
 
Example 28
Project: ESPD   File: Emitter.java   Source Code and License 5 votes vote down vote up
@Override
public void draw() {
	if (lightMode) {
		GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
		super.draw();
		GLES20.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
	} else {
		super.draw();
	}
}
 
Example 29
Project: G2Dj   File: GL.java   Source Code and License 5 votes vote down vote up
public static void glVertexAttribPointer(final int aAttributeIndex, final int aAttributeSize, final int aType, final Boolean aNormalized, final int aStride, final int aOffset )
{
    //.if DESKTOP
    //|gl.glVertexAttribPointer(aAttributeIndex,aAttributeSize,aType,aNormalized,aStride,aOffset);
    //.elseif ANDROID
    GLES20.glVertexAttribPointer(aAttributeIndex,aAttributeSize,aType,aNormalized,aStride,aOffset);
    //.endif
    
}
 
Example 30
Project: PaoMovie   File: GPUImageFilter.java   Source Code and License 5 votes vote down vote up
protected void setPoint(final int location, final PointF point) {
    runOnDraw(new Runnable() {

        @Override
        public void run() {
            float[] vec2 = new float[2];
            vec2[0] = point.x;
            vec2[1] = point.y;
            GLES20.glUniform2fv(location, 1, vec2, 0);
        }
    });
}
 
Example 31
Project: AppRTC-Android   File: GlRectDrawer.java   Source Code and License 5 votes vote down vote up
/**
 * Draw an OES texture frame with specified texture transformation matrix. Required resources are
 * allocated at the first call to this function.
 */
@Override
public void drawOes(int oesTextureId, float[] texMatrix, int frameWidth, int frameHeight,
    int viewportX, int viewportY, int viewportWidth, int viewportHeight) {
  prepareShader(OES_FRAGMENT_SHADER_STRING, texMatrix);
  GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
  // updateTexImage() may be called from another thread in another EGL context, so we need to
  // bind/unbind the texture in each draw call so that GLES understads it's a new texture.
  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, oesTextureId);
  drawRectangle(viewportX, viewportY, viewportWidth, viewportHeight);
  GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
}
 
Example 32
Project: react-native-scan-doc   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
    //Log.i(LOGTAG, "onDrawFrame start");

    if (!mHaveFBO)
        return;

    synchronized(this) {
        if (mUpdateST) {
            mSTexture.updateTexImage();
            mUpdateST = false;
        }

        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

        CameraTextureListener texListener = mView.getCameraTextureListener();
        if(texListener != null) {
            //Log.d(LOGTAG, "haveUserCallback");
            // texCamera(OES) -> texFBO
            drawTex(texCamera[0], true, FBO[0]);

            // call user code (texFBO -> texDraw)
            boolean modified = texListener.onCameraTexture(texFBO[0], texDraw[0], mCameraWidth, mCameraHeight);

            if(modified) {
                // texDraw -> screen
                drawTex(texDraw[0], false, 0);
            } else {
                // texFBO -> screen
                drawTex(texFBO[0], false, 0);
            }
        } else {
            Log.d(LOGTAG, "texCamera(OES) -> screen");
            // texCamera(OES) -> screen
            drawTex(texCamera[0], true, 0);
        }
        //Log.i(LOGTAG, "onDrawFrame end");
    }
}
 
Example 33
Project: UNIST-pixel-dungeon   File: Vertexbuffer.java   Source Code and License 5 votes vote down vote up
public Vertexbuffer( FloatBuffer vertices ) {
	synchronized (buffers) {
		int[] ptr = new int[1];
		GLES20.glGenBuffers(1, ptr, 0);
		id = ptr[0];

		this.vertices = vertices;
		buffers.add(this);

		updateStart = 0;
		updateEnd = vertices.limit();
	}
}
 
Example 34
Project: PaoMovie   File: MagicImageDisplay.java   Source Code and License 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 gl) {
	GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
	if(mTextureId == OpenGLUtils.NO_TEXTURE)
		mTextureId = OpenGLUtils.loadTexture(mMagicSDK.getBitmap(), OpenGLUtils.NO_TEXTURE);
	if(mFilters == null){
		mImageInput.onDrawFrame(mTextureId, mGLCubeBuffer, mGLTextureBuffer);
	}else{
		mFilters.onDrawFrame(mTextureId, mGLCubeBuffer, mGLTextureBuffer);
	}
}
 
Example 35
Project: FaceDetectDemo   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
private void initTexOES(int[] tex) {
    if(tex.length == 1) {
        GLES20.glGenTextures(1, tex, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    }
}
 
Example 36
Project: PaoMovie   File: MagicTenderFilter.java   Source Code and License 5 votes vote down vote up
protected void onDrawArraysPre(){
	if (mToneCurveTexture[0] != -1){
		GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
		GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3);
    }
	if (mMaskGrey1TextureId != -1){
		GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId);
		GLES20.glUniform1i(mMaskGrey1UniformLocation, 4);
    }
}
 
Example 37
Project: android-imaging-utils   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
private void initTexOES(int[] tex) {
    if(tex.length == 1) {
        GLES20.glGenTextures(1, tex, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    }
}
 
Example 38
Project: fingerblox   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
private void initTexOES(int[] tex) {
    if(tex.length == 1) {
        GLES20.glGenTextures(1, tex, 0);
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    }
}
 
Example 39
Project: MediaCodecRecorder   File: GLSurfaceFilter.java   Source Code and License 5 votes vote down vote up
/**
 * draw specific texture with specific texture matrix
 *
 * @param textureId texture ID
 * @param texMatrix texture matrix if this is null, the last one use(we don't check size of this array and needs at least 16 of float)
 */
public void draw(final int textureId, final float[] mvpMatrix, final float[] texMatrix) {
    // Select the program.
    GLES20.glUseProgram(hProgram);

    // Set the texture.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(mTextureTarget, textureId);


    // Copy the texture transformation matrix over.
    GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, texMatrix, 0);

    // Copy the model / view / projection matrix over.
    GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mvpMatrix, 0);

    // Enable the "aPosition" vertex attribute.
    GLES20.glEnableVertexAttribArray(maPositionLoc);

    // Connect vertexBuffer to "aPosition".
    GLES20.glVertexAttribPointer(maPositionLoc, mCoordsPerVertex,
            GLES20.GL_FLOAT, false, mVertexStride, FULL_RECTANGLE_BUF);

    // Enable the "aTextureCoord" vertex attribute.
    GLES20.glEnableVertexAttribArray(maTextureCoordLoc);

    // Connect texBuffer to "aTextureCoord".
    GLES20.glVertexAttribPointer(maTextureCoordLoc, mCoordsPerVertex,
            GLES20.GL_FLOAT, false, mTexCoordStride, FULL_RECTANGLE_TEX_BUF);

    // Draw the rect.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mVertexCount);

    // Done -- disable vertex array, texture, and program.
    GLES20.glDisableVertexAttribArray(maPositionLoc);
    GLES20.glDisableVertexAttribArray(maTextureCoordLoc);
    GLES20.glBindTexture(mTextureTarget, 0);
}
 
Example 40
Project: fingerblox   File: CameraGLRendererBase.java   Source Code and License 5 votes vote down vote up
private void deleteFBO()
{
    Log.d(LOGTAG, "deleteFBO("+mFBOWidth+"x"+mFBOHeight+")");
    GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
    GLES20.glDeleteFramebuffers(1, FBO, 0);

    deleteTex(texFBO);
    deleteTex(texDraw);
    mFBOWidth = mFBOHeight = 0;
}