android.opengl.GLUtils Java Examples

The following examples show how to use android.opengl.GLUtils. 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 File: Model3D.java    From augmentedreality with 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 #2
Source File: Texture.java    From smartGL with 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 #3
Source File: TexCubeSmallGLUT.java    From opengl with 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 #4
Source File: MediaEffectsFragment.java    From graphics-samples with 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 File: AndroidBitmap.java    From trekarta with 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
Source File: StaticTriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
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 File: GlUtil.java    From PLDroidMediaStreaming with 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 #8
Source File: EglUtil.java    From Mp4Composer-android with 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 #9
Source File: EffectsFilterActivity.java    From ImageEffects with Eclipse Public License 1.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 #10
Source File: UploadedTexture.java    From PhotoMovie with 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 File: GLUtil.java    From PhotoMovie with 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 File: GLHelper.java    From PhotoMovie with 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 File: EglUtil.java    From SimpleVideoEdit with 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 #14
Source File: ImageFilterView.java    From PhotoEditor with 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 #15
Source File: GLSurface.java    From libcommon with 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 #16
Source File: OpenGlUtils.java    From TikTok with 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 #17
Source File: GlOverlayFilter.java    From GPUVideo-android with 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 #18
Source File: RRGLTexture.java    From RedReader with 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 #19
Source File: GlUtil.java    From sealrtc-android with 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 #20
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with 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 #21
Source File: IntroActivity.java    From Telegram-FOSS with 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 #22
Source File: Page.java    From android-PageFlip with 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 #23
Source File: GLSurface.java    From libcommon with 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 #24
Source File: TextureUtils.java    From In77Camera with MIT License 5 votes vote down vote up
public static int loadTextureWithOldTexId(final Bitmap img, final int usedTexId) {
    int textures[] = new int[1];
    if (usedTexId == GLEtc.NO_TEXTURE) {
        return getTextureFromBitmap(img,null);
    } else {
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId);
        GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img);
        textures[0] = usedTexId;
    }
    return textures[0];
}
 
Example #25
Source File: IntroActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 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 #26
Source File: MyOSDReceiverRenderer.java    From myMediaCodecPlayer-for-FPV with MIT License 5 votes vote down vote up
public void drawOverlay(float[] viewM) {

            GLES20.glEnable(GLES20.GL_BLEND);
            GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
            //Update every second frame (at 30fps)
            if(i2==1){
                GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, UpdateOverdrawValues[0],0,bmp);
                UpdateOverdrawLayer=true;
                i2=4;
            }else{i2-=1;}
            GLES20.glUseProgram(mProgram2);
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
            GLES20.glEnableVertexAttribArray(maPositionHandle2);
            GLES20.glVertexAttribPointer(maPositionHandle2, 3, GLES20.GL_FLOAT, false,
                    TRIANGLE_VERTICES_DATA_STRIDE_BYTES, 0);
            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, buffers[1]);
            GLES20.glEnableVertexAttribArray(maTextureHandle2);
            GLES20.glVertexAttribPointer(maTextureHandle2, 3, GLES20.GL_FLOAT, false,
                    TRIANGLE_VERTICES_DATA_STRIDE_BYTES, 3 * mBytesPerFloat);
            GLES20.glUniform1i(mSamplerLoc, 0);
            if(true){
                /*
                Matrix.multiplyMM(mMVPM, 0, viewM, 0, mOSDModelM, 0);
                Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);*/
                Matrix.multiplyMM(mMVPM,0,mProjM,0,viewM,0);
                GLES20.glUniformMatrix4fv(mMVPMatrixHandle2, 1, false, mMVPM, 0);
                GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 6 * 14);
            }
            if(enable_height){
                Matrix.multiplyMM(mMVPM, 0, viewM, 0, mHeightModelM, 0);
                Matrix.multiplyMM(mMVPM, 0, mProjM, 0, mMVPM, 0);
                GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPM, 0);
                GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 6 * 14, 10*6);
            }
            GLES20.glDisableVertexAttribArray(maPositionHandle2);
            GLES20.glDisableVertexAttribArray(maTextureHandle2);
            GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
            GLES20.glDisable(GLES20.GL_BLEND);
        }
 
Example #27
Source File: GLES20Canvas.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@Override
public void texSubImage2D(BasicTexture texture, int xOffset, int yOffset, Bitmap bitmap,
        int format, int type) {
    int target = texture.getTarget();
    GLES20.glBindTexture(target, texture.getId());
    checkError();
    GLUtils.texSubImage2D(target, 0, xOffset, yOffset, bitmap, format, type);
}
 
Example #28
Source File: GLUtil.java    From react-native-3d-model-view with MIT License 5 votes vote down vote up
public static int loadTexture(final InputStream is) {
	Log.v("GLUtil", "Loading texture '" + is + "' from stream...");

	final int[] textureHandle = new int[1];

	GLES20.glGenTextures(1, textureHandle, 0);
	GLUtil.checkGlError("glGenTextures");

	if (textureHandle[0] != 0) {
		Log.i("GLUtil", "Handler: " + textureHandle[0]);

		final BitmapFactory.Options options = new BitmapFactory.Options();
		// By default, Android applies pre-scaling to bitmaps depending on the resolution of your device and which
		// resource folder you placed the image in. We don’t want Android to scale our bitmap at all, so to be sure,
		// we set inScaled to false.
		options.inScaled = false;

		// Read in the resource
		final Bitmap bitmap = BitmapFactory.decodeStream(is, null, options);
		if (bitmap == null) {
			throw new RuntimeException("couldnt load bitmap");
		}

		// Bind to the texture in OpenGL
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
		GLUtil.checkGlError("glBindTexture");
		GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
		GLUtil.checkGlError("texImage2D");
		bitmap.recycle();
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

	}

	if (textureHandle[0] == 0) {
		throw new RuntimeException("Error loading texture.");
	}

	return textureHandle[0];
}
 
Example #29
Source File: ParticleRenderer.java    From ParticleView with Apache License 2.0 5 votes vote down vote up
private void setupTextures(TextureAtlas atlas) {
    int[] names = new int[1];
    glGenTextures(1, names, 0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, names[0]);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    GLUtils.texImage2D(GL_TEXTURE_2D, 0, Bitmap.createBitmap(atlas.getWidth(), atlas.getHeight(),
            Bitmap.Config.ARGB_8888), 0);

    List<TextureAtlas.Region> regions = atlas.getRegions();
    textureCoordsCacheArray = new float[regions.size() * 8];
    final int k = 8;
    float atlasWidth = atlas.getWidth();
    float atlasHeight = atlas.getHeight();
    for (int i = 0; i < regions.size(); i++) {
        TextureAtlas.Region r = regions.get(i);
        GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, r.x, r.y, r.bitmap);
        float x0 = r.x / atlasWidth;
        float y0 = r.y / atlasHeight;
        float x1 = x0 + r.bitmap.getWidth() / atlasWidth;
        float y1 = y0 + r.bitmap.getHeight() / atlasHeight;
        List<Float> coords = Arrays.asList(x0, y0, x0, y1, x1, y1, x1, y0);
        if (r.cwRotated) {
            Collections.rotate(coords, 2);
        }
        for (int j = 0; j < coords.size(); j++) {
            textureCoordsCacheArray[i * k + j] = coords.get(j);
        }
    }
}
 
Example #30
Source File: myGLTextureView.java    From opengl with Apache License 2.0 5 votes vote down vote up
private void checkCurrent() {
    if (!mEglContext.equals(mEgl.eglGetCurrentContext())
            || !mEglSurface.equals(mEgl
            .eglGetCurrentSurface(EGL10.EGL_DRAW))) {
        checkEglError();
        if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface,
                mEglSurface, mEglContext)) {
            throw new RuntimeException(
                    "eglMakeCurrent failed "
                            + GLUtils.getEGLErrorString(mEgl
                            .eglGetError()));
        }
        checkEglError();
    }
}