Java Code Examples for android.opengl.GLUtils

The following examples show how to use android.opengl.GLUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: GPUVideo-android   Source File: GlOverlayFilter.java    License: MIT License 6 votes vote down vote up
@Override
public void onDraw() {
    if (bitmap == null) {
        createBitmap();
    }
    if (bitmap.getWidth() != inputResolution.getWidth() || bitmap.getHeight() != inputResolution.getHeight()) {
        createBitmap();
    }

    bitmap.eraseColor(Color.argb(0, 0, 0, 0));
    Canvas bitmapCanvas = new Canvas(bitmap);
    bitmapCanvas.scale(1, -1, bitmapCanvas.getWidth() / 2, bitmapCanvas.getHeight() / 2);
    drawCanvas(bitmapCanvas);

    int offsetDepthMapTextureUniform = getHandle("oTexture");// 3

    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    if (bitmap != null && !bitmap.isRecycled()) {
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, bitmap, 0);
    }

    GLES20.glUniform1i(offsetDepthMapTextureUniform, 3);
}
 
Example 2
Source Project: opengl   Source File: TexCubeSmallGLUT.java    License: Apache License 2.0 6 votes vote down vote up
void setTex (GL10 gl, Context c, int textureID, int drawableID) {
mCoordBuffer = getFloatBufferFromFloatArray(texCoords);

mTextureID = textureID;

gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

Bitmap bitmap = BitmapFactory.decodeResource(c.getResources(), drawableID);
Bitmap bitmap256 = Bitmap.createScaledBitmap(bitmap, 256, 256, false);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap256, 0);
bitmap.recycle();
bitmap256.recycle();

       gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
               GL10.GL_NEAREST);
       gl.glTexParameterf(GL10.GL_TEXTURE_2D,
               GL10.GL_TEXTURE_MAG_FILTER,
               GL10.GL_LINEAR);
       texEnabled = true;
       
   }
 
Example 3
Source Project: smartGL   Source File: Texture.java    License: Apache License 2.0 6 votes vote down vote up
boolean bindTexture() {
	if ((mBitmap != null) && (!mBitmap.isRecycled())) {
		GLES20.glGenTextures(1, mId, 0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mId[0]);
		GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBitmap, 0); // GLES20.GL_RGBA
		if (mRecycleWhenBinded) {
			mBitmap.recycle();
			mBitmap = null;
		}
		return true;
	}
	return false;
}
 
Example 4
Source Project: graphics-samples   Source File: MediaEffectsFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void loadTextures() {
    // Generate textures
    GLES20.glGenTextures(2, mTextures, 0);

    // Load input bitmap
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy);
    mImageWidth = bitmap.getWidth();
    mImageHeight = bitmap.getHeight();
    mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);

    // Upload to texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

    // Set texture parameters
    GLToolbox.initTexParams();
}
 
Example 5
Source Project: trekarta   Source File: AndroidBitmap.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void uploadToTexture(boolean replace) {
    if (mBitmap.isRecycled()) {
        log.error("Attempted to upload recycled bitmap to texture");
        return;
    }
    int format = GLUtils.getInternalFormat(mBitmap);
    int type = GLUtils.getType(mBitmap);

    if (replace)
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0,
                mBitmap, format, type);
    else
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format,
                mBitmap, type, 0);
}
 
Example 6
public void load(GL10 gl) {
    InputStream is = mContext.getResources().openRawResource(
            R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
}
 
Example 7
Source Project: Mp4Composer-android   Source File: EglUtil.java    License: MIT License 6 votes vote down vote up
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) {
    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);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
        textures[0] = usedTexId;
    }
    if (recycle) {
        img.recycle();
    }
    return textures[0];
}
 
Example 8
Source Project: PLDroidMediaStreaming   Source File: GlUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static int createTexture(int textureTarget, @Nullable Bitmap bitmap, int minFilter,
                                int magFilter, int wrapS, int wrapT) {
    int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);
    GlUtil.checkGlError("glGenTextures");
    GLES20.glBindTexture(textureTarget, textureHandle[0]);
    GlUtil.checkGlError("glBindTexture " + textureHandle[0]);
    GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MIN_FILTER, minFilter);
    GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MAG_FILTER, magFilter); //线性插值
    GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_S, wrapS);
    GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_T, wrapT);

    if (bitmap != null) {
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    }

    GlUtil.checkGlError("glTexParameter");
    return textureHandle[0];
}
 
Example 9
private void loadTextures() {
	// Generate textures
	GLES20.glGenTextures(2, mTextures, 0);

	// Load input bitmap
	Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy);
	mImageWidth = bitmap.getWidth();
	mImageHeight = bitmap.getHeight();
	mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);

	// Upload to texture
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
	GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

	// Set texture parameters
	GLToolbox.initTexParams();
}
 
Example 10
Source Project: PhotoMovie   Source File: UploadedTexture.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates the content on GPU's memory.
 *
 * @param canvas
 */
public void updateContent(GLESCanvas canvas) {
    if (!isLoaded()) {
        if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT || canvas == null) {
            return;
        }
        uploadToCanvas(canvas);
    } else if (!mContentValid) {
        Bitmap bitmap = getBitmap();
        int format = GLUtils.getInternalFormat(bitmap);
        int type = GLUtils.getType(bitmap);
        canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type);
        freeBitmap();
        mContentValid = true;
    }
}
 
Example 11
Source Project: PhotoMovie   Source File: GLUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) {
    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);

        android.opengl.GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        android.opengl.GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
        textures[0] = usedTexId;
    }
    if (recycle) {
        img.recycle();
    }
    return textures[0];
}
 
Example 12
Source Project: PhotoMovie   Source File: GLHelper.java    License: Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Bitmap bitmap, final int usedTextureId) {
    int[] textures = new int[1];
    if (usedTextureId == 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);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTextureId);
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, bitmap);
        textures[0] = usedTextureId;
    }
    return textures[0];
}
 
Example 13
Source Project: TikTok   Source File: OpenGlUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Bitmap img, final int usedTexId, boolean recyled) {
if(img == 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);

          GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
      } else {
          GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
          GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
          textures[0] = usedTexId;
      }
      if(recyled)
      	img.recycle();
      return textures[0];
  }
 
Example 14
Source Project: SimpleVideoEdit   Source File: EglUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) {
    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);

        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
        textures[0] = usedTexId;
    }
    if (recycle) {
        img.recycle();
    }
    return textures[0];
}
 
Example 15
Source Project: PhotoEditor   Source File: ImageFilterView.java    License: MIT License 6 votes vote down vote up
private void loadTextures() {
    // Generate textures
    GLES20.glGenTextures(2, mTextures, 0);

    // Load input bitmap
    if (mSourceBitmap != null) {
        mImageWidth = mSourceBitmap.getWidth();
        mImageHeight = mSourceBitmap.getHeight();
        mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);

        // Upload to texture
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mSourceBitmap, 0);

        // Set texture parameters
        GLToolbox.initTexParams();
    }
}
 
Example 16
Source Project: libcommon   Source File: GLSurface.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Bitmapから画像をテクスチャに読み込む
 * @param bitmap
 */
@Override
public void loadBitmap(@NonNull final Bitmap bitmap) {
	final int width = bitmap.getWidth();
	final int height = bitmap.getHeight();
	if ((width > mTexWidth) || (height > mTexHeight)) {
		mWidth = width;
		mHeight = height;
		releaseFrameBuffer();
		createFrameBuffer(width, height);
	}
	GLES30.glActiveTexture(TEX_UNIT);
	GLES30.glBindTexture(TEX_TARGET, mFBOTexId);
	GLUtils.texImage2D(TEX_TARGET, 0, bitmap, 0);
	GLES30.glBindTexture(TEX_TARGET, 0);
	// initialize texture matrix
	Matrix.setIdentityM(mTexMatrix, 0);
	mTexMatrix[0] = width / (float)mTexWidth;
	mTexMatrix[5] = height / (float)mTexHeight;
}
 
Example 17
Source Project: RedReader   Source File: RRGLTexture.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static int loadTexture(final Bitmap bitmap, final boolean smooth) {

		final int[] textureHandle = new int[1];
		GLES20.glGenTextures(1, textureHandle, 0);

		if(textureHandle[0] == 0) {
			throw new RuntimeException("OpenGL error: glGenTextures failed.");
		}

		final int filter = smooth ? GLES20.GL_LINEAR : GLES20.GL_NEAREST;

		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, filter);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, filter);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

		return textureHandle[0];
	}
 
Example 18
Source Project: sealrtc-android   Source File: GlUtil.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a texture from bitmap.
 *
 * @param bmp bitmap data
 * @return Handle to texture.
 */
public static int createImageTexture(Bitmap bmp) {
    int[] textureHandles = new int[1];
    int textureHandle;

    GLES20.glGenTextures(1, textureHandles, 0);
    textureHandle = textureHandles[0];
    GlUtil.checkGlError("glGenTextures");

    // Bind the texture handle to the 2D texture target.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);

    // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering
    // is smaller or larger than the source image.
    GLES20.glTexParameteri(
            GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(
            GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GlUtil.checkGlError("loadImageTexture");

    // Load the data from the buffer into the texture handle.
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, /*level*/ 0, bmp, 0);
    GlUtil.checkGlError("loadImageTexture");

    return textureHandle;
}
 
Example 19
Source Project: Telegram-FOSS   Source File: IntroActivity.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    if (!initied) {
        return;
    }

    if (!eglContext.equals(egl10.eglGetCurrentContext()) || !eglSurface.equals(egl10.eglGetCurrentSurface(EGL10.EGL_DRAW))) {
        if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            if (BuildVars.LOGS_ENABLED) {
                FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
            }
            return;
        }
    }
    float time = (System.currentTimeMillis() - currentDate) / 1000.0f;
    Intro.setPage(currentViewPagerPage);
    Intro.setDate(time);
    Intro.onDrawFrame();
    egl10.eglSwapBuffers(eglDisplay, eglSurface);

    postRunnable(() -> drawRunnable.run(), 16);
}
 
Example 20
Source Project: android-PageFlip   Source File: Page.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Set the back texture with given bitmap
 * <p>If given bitmap is null, the back texture will be same with the first
 * texture</p>
 *
 * @param b Bitmap object for creating back texture
 */
public void setBackTexture(Bitmap b) {
    if (b == null) {
        // back texture is same with the first texture
        if (mTexIDs[BACK_TEXTURE_ID] != INVALID_TEXTURE_ID) {
            mUnusedTexIDs[mUnusedTexSize++] = mTexIDs[BACK_TEXTURE_ID];
        }
        mTexIDs[BACK_TEXTURE_ID] = INVALID_TEXTURE_ID;
    }
    else {
        // compute mask color
        int color = PageFlipUtils.computeAverageColor(b, 50);
        maskColor[BACK_TEXTURE_ID][0] = Color.red(color) / 255.0f;
        maskColor[BACK_TEXTURE_ID][1] = Color.green(color) / 255.0f;
        maskColor[BACK_TEXTURE_ID][2] = Color.blue(color) / 255.0f;

        glGenTextures(1, mTexIDs, BACK_TEXTURE_ID);
        glBindTexture(GL_TEXTURE_2D, mTexIDs[BACK_TEXTURE_ID]);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        GLUtils.texImage2D(GL_TEXTURE_2D, 0, b, 0);
    }
}
 
Example 21
Source Project: libcommon   Source File: GLSurface.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Bitmapから画像をテクスチャに読み込む
 * @param bitmap
 */
@Override
public void loadBitmap(@NonNull final Bitmap bitmap) {
	final int width = bitmap.getWidth();
	final int height = bitmap.getHeight();
	if ((width > mTexWidth) || (height > mTexHeight)) {
		mWidth = width;
		mHeight = height;
		releaseFrameBuffer();
		createFrameBuffer(width, height);
	}
	GLES20.glActiveTexture(TEX_UNIT);
	GLES20.glBindTexture(TEX_TARGET, mFBOTexId);
	GLUtils.texImage2D(TEX_TARGET, 0, bitmap, 0);
	GLES20.glBindTexture(TEX_TARGET, 0);
	// initialize texture matrix
	Matrix.setIdentityM(mTexMatrix, 0);
	mTexMatrix[0] = width / (float)mTexWidth;
	mTexMatrix[5] = height / (float)mTexHeight;
}
 
Example 22
Source Project: Building-Android-UIs-with-Custom-Views   Source File: GLDrawer.java    License: MIT License 6 votes vote down vote up
private void attachBitmapToTexture(int textureId, Bitmap textureBitmap) {
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_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);

    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textureBitmap, 0);
}
 
Example 23
Source Project: augmentedreality   Source File: Model3D.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void init(GL10 gl){
	int[]  tmpTextureID = new int[1];

	Iterator<Material> materialI = model.getMaterials().values().iterator();
	while (materialI.hasNext()) {
		Material material = (Material) materialI.next();
		if(material.hasTexture()) {

			gl.glGenTextures(1, tmpTextureID, 0);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, tmpTextureID[0]);
			textureIDs.put(material, tmpTextureID[0]);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, material.getTexture(),0);
			material.getTexture().recycle();
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 
		}
	}
}
 
Example 24
Source Project: DeviceConnect-Android   Source File: SphericalViewRenderer.java    License: MIT License 5 votes vote down vote up
/**
 * Texture setting method
 *
 * @param texture Setting texture
 */
public void loadTexture(final Bitmap texture) {
    GLES20.glGenTextures(1, mTextures, 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);

    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, texture, 0);
}
 
Example 25
@Override
public void run()
{
    if (!initied)
    {
        return;
    }

    if (!eglContext.equals(egl10.eglGetCurrentContext()) || !eglSurface.equals(egl10.eglGetCurrentSurface(EGL10.EGL_DRAW)))
    {
        if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext))
        {
            if (BuildVars.LOGS_ENABLED)
            {
                FileLog.e("eglMakeCurrent failed " + GLUtils.getEGLErrorString(egl10.eglGetError()));
            }
            return;
        }
    }
    float time = (System.currentTimeMillis() - currentDate) / 1000.0f;
    Intro.setPage(currentViewPagerPage);
    Intro.setDate(time);
    Intro.onDrawFrame();
    egl10.eglSwapBuffers(eglDisplay, eglSurface);

    postRunnable(() -> drawRunnable.run(), 16);
}
 
Example 26
private void loadTexture(int resId, int index)
{
    Drawable drawable = getResources().getDrawable(resId);
    if (drawable instanceof BitmapDrawable)
    {
        Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
        GLES20.glBindTexture(GL10.GL_TEXTURE_2D, textures[index]);
        GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
        GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    }
}
 
Example 27
Source Project: PhotoMovie   Source File: GLES20Canvas.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initializeTexture(BasicTexture texture, Bitmap bitmap) {
    int target = texture.getTarget();
    GLES20.glBindTexture(target, texture.getId());
    checkError();
    GLUtils.texImage2D(target, 0, bitmap, 0);
}
 
Example 28
Source Project: codeexamples-android   Source File: LabelMaker.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Call to end adding labels. Must be called before drawing starts.
 *
 * @param gl
 */
public void endAdding(GL10 gl) {
    checkState(STATE_ADDING, STATE_INITIALIZED);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
    // Reclaim storage used by bitmap and canvas.
    mBitmap.recycle();
    mBitmap = null;
    mCanvas = null;
}
 
Example 29
Source Project: TikTok   Source File: OpenGlUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int loadTexture(final Context context, final String name){
	final int[] textureHandle = new int[1];
	
	GLES20.glGenTextures(1, textureHandle, 0);
	
	if (textureHandle[0] != 0){

		// Read in the resource
		final Bitmap bitmap = getImageFromAssetsFile(context,name);
					
		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		
		// Set filtering
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
		// Load the bitmap into the bound texture.
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		
		// Recycle the bitmap, since its data has been loaded into OpenGL.
		bitmap.recycle();						
	}
	
	if (textureHandle[0] == 0){
		throw new RuntimeException("Error loading texture.");
	}
	
	return textureHandle[0];
}
 
Example 30
Source Project: TikTok   Source File: OpenGlUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static int loadTexture(final Context context, final String name){
	final int[] textureHandle = new int[1];
	
	GLES20.glGenTextures(1, textureHandle, 0);
	
	if (textureHandle[0] != 0){

		// Read in the resource
		final Bitmap bitmap = getImageFromAssetsFile(context,name);
					
		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		
		// Set filtering
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
		// Load the bitmap into the bound texture.
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		
		// Recycle the bitmap, since its data has been loaded into OpenGL.
		bitmap.recycle();						
	}
	
	if (textureHandle[0] == 0){
		throw new RuntimeException("Error loading texture.");
	}
	
	return textureHandle[0];
}