private int makeTexture(Bitmap bmp) { //テクスチャメモリの確保 int[] textureIds=new int[1]; GLES20.glGenTextures(1,textureIds,0); //テクスチャへのビットマップ指定 GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,textureIds[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D,0,bmp,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_NEAREST); return textureIds[0]; }
public WaterMarkFilter setMark(final Bitmap bmp){ runOnGLThread(new Runnable() { @Override public void run() { if(bmp!=null){ if(markTextureId==-1){ markTextureId=GpuUtils.createTextureID(false); }else{ GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,markTextureId); } GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,0,bmp,0); bmp.recycle(); }else{ if(markTextureId!=-1){ GLES20.glDeleteTextures(1,new int[]{markTextureId},0); } } } }); return this; }
/** * Loads the texture. * * @param gl */ public void loadGLTexture(GL10 gl) { if (mBitmap == null) { System.out.println("Texture not loaded yet"); return; } int[] textures = new int[1]; gl.glGenTextures(1, textures, 0); mTextureId = textures[0]; gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); // release the bitmap mBitmap.recycle(); loaded(); }
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); }
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]; }
private void initGL() { egl = (EGL10) EGLContext.getEGL(); eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(eglDisplay, version); EGLConfig eglConfig = chooseEglConfig(); eglContext = createContext(egl, eglDisplay, eglConfig); eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, texture, null); if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) { throw new RuntimeException("GL Error: " + GLUtils.getEGLErrorString(egl.eglGetError())); } if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) { throw new RuntimeException("GL Make current error: " + GLUtils.getEGLErrorString(egl.eglGetError())); } }
private EGLConfig chooseEglConfig() { int[] configsCount = new int[1]; EGLConfig[] configs = new EGLConfig[1]; int[] configSpec = getConfig(); if (!egl.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) { throw new IllegalArgumentException("Failed to choose config: " + GLUtils.getEGLErrorString(egl.eglGetError())); } else if (configsCount[0] > 0) { return configs[0]; } return null; }
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(); }
public int[] load() { if (textStreamObject != null) { textureId = new int[textStreamObject.getNumFrames()]; GlUtil.createTextures(textStreamObject.getNumFrames(), textureId, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, textStreamObject.getImageBitmap(), 0); textStreamObject.recycle(); } else if (imageStreamObject != null) { textureId = new int[imageStreamObject.getNumFrames()]; GlUtil.createTextures(imageStreamObject.getNumFrames(), textureId, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[0]); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, imageStreamObject.getImageBitmap(), 0); imageStreamObject.recycle(); } else if (gifStreamObject != null) { textureId = new int[gifStreamObject.getNumFrames()]; GlUtil.createTextures(gifStreamObject.getNumFrames(), textureId, 0); for (int i = 0; i < gifStreamObject.getNumFrames(); i++) { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId[i]); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, gifStreamObject.getGifBitmaps()[i], 0); } gifStreamObject.recycle(); } else { textureId = new int[] { -1 }; } return textureId; }
/** * @param textureTarget Texture类型。 * 1. 相机用 GLES11Ext.GL_TEXTURE_EXTERNAL_OES * 2. 图片用GLES20.GL_TEXTURE_2D * @param minFilter 缩小过滤类型 (1.GL_NEAREST ; 2.GL_LINEAR) * @param magFilter 放大过滤类型 * @param wrapS X方向边缘环绕 * @param wrapT Y方向边缘环绕 * @return 返回创建的 Texture ID */ 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]; }
/** * 将bitmap绑定为纹理 * * @param bitmap * @return */ public static int bindBitmap(Bitmap bitmap) { int[] tex = new int[1]; GLES20.glGenTextures(1, tex, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex[0]); 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, bitmap, 0); return tex[0]; }
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]; }
public static int loadTexture(Bitmap bitmap, boolean recycle) { if (bitmap == null) { return 0; } int textures[] = new int[1]; 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); if (recycle) { bitmap.recycle(); } return textures[0]; }
@Override public int[] loadTexture(Vfs vfs, String filePath) { InputStream inputStream = vfs.getInputStream(filePath); if (inputStream == null) { throw new GLTextureNotFoundException(filePath); } Bitmap bitmap = BitmapFactory.decodeStream(inputStream); int width = bitmap.getWidth(); int height = bitmap.getHeight(); if (Context.isUsePack() && (!isPOT(width) || !isPOT(height))) { throw new RuntimeException("Texture size is not power of two: " + filePath); } GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); return new int[]{width, height}; }
public void run() { Bitmap bitmap; try { bitmap = captureView(view); } catch (Exception e) { return; } if (yflip) { Matrix matrix = new Matrix(); matrix.postScale(1, -1); boolean hasAlpha = bitmap.hasAlpha(); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); bitmap.setHasAlpha(hasAlpha); } int[] textures = new int[1]; glGenTextures(1, textures, 0); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); GLUtils.texImage2D(GL_TEXTURE_2D, 0, bitmap, 0); this.attachTexture(textures[0]); }
private int createTexture(Bitmap bitmap, boolean recycled, int target) { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); checkGLESError("gen texture"); GLES20.glBindTexture(target, textures[0]); checkGLESError("bind texture"); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(target, 0, bitmap, 0); if (recycled && !bitmap.isRecycled()) { bitmap.recycle(); } checkGLESError("tex image 2d"); return textures[0]; }
public int createBmpTexture(GL10 gl, Bitmap bitmap) { int nNextAvailableId = mtextureMgr.getFirstUninitTextureId(); if (nNextAvailableId >= 0) { // -1 means no available texture id. //...and bind it to our array gl.glBindTexture(GL10.GL_TEXTURE_2D, mtextureMgr.mtextures[nNextAvailableId]); //Create Nearest Filtered Texture 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); //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); //gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); mtextureMgr.markTextureIdUsed(nNextAvailableId); } return nNextAvailableId; }
/** * Updates the content on GPU's memory. * @param canvas */ public void updateContent(GLCanvas canvas) { if (!isLoaded()) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { 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; } }
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]; }
public static int loadTexture(final Bitmap bmp) { int[] textureHandle = new int[1]; GLES20.glGenTextures(1, textureHandle, 0); if(textureHandle[0] != 0) { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]); 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); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0); }else{ throw new RuntimeException("Error loading texture"); } return textureHandle[0]; }
/** Bitmapからテクスチャを読み込む */ public void loadBitmap(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.glBindTexture(TEX_TARGET, mFBOTextureName); 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; }
public void load() { final int[] textureHandle = new int[1]; GLES20.glGenTextures(1, textureHandle, 0); if (textureHandle[0] != 0) { InputStream is = Assets.openInputStream(source); final Bitmap bitmap = BitmapFactory.decodeStream(is); // 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_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); // GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); // 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."); } textureDataHandle = textureHandle[0]; textureTarget = GLES20.GL_TEXTURE_2D; }
@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { super.onSurfaceCreated(glUnused, config); Bitmap bitmap = BitmapFactory.decodeResource(mSurfaceView.getResources(), R.drawable.video_brightness_6_white_36dp); //创建bitmap GLES20.glGenTextures(1, mTexturesBitmap, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); 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); bitmap.recycle(); }
public void setPicture(Bitmap bitmap) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); float widthFactor, heightFactor; if (width > height) { widthFactor = width / (float) height; heightFactor = 1; } else { // height >= width widthFactor = 1; heightFactor = height / (float) width; } setVertexData(widthFactor, heightFactor); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mGLTexture[0]); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); }
private void bind(GL10 gl) { if (handle == null) { handle = new int[1]; gl.glGenTextures(1, handle, 0); reload = true; } gl.glBindTexture(GL10.GL_TEXTURE_2D, handle[0]); 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_NEAREST); synchronized (mutex) { if (reload) { GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmapFront, 0); reload = false; } } }
/** * 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); } }
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); gl.glClearColor(0xff, 0xff, 0xff, 0xff); gl.glEnable(GL10.GL_CULL_FACE); gl.glShadeModel(GL10.GL_SMOOTH); gl.glEnable(GL10.GL_DEPTH_TEST); gl.glClearDepthf(1.0f); gl.glDepthFunc(GL10.GL_LEQUAL); gl.glEnable(GL10.GL_TEXTURE_2D); gl.glGenTextures(1, textureids, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, textureids[0]); GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, GLImage.iBitmap, 0); 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); }
protected void loadGLTexture() { //Generate a number of texture, texture pointer... int textures[] = new int[1]; GLES20.glGenTextures(1, textures, 0); Bitmap bitmap = getBitmapFromAsset(context, pathToTexture); //...and bind it to our array activeTexture = stack.removeFirst(); GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + activeTexture); GLES20.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); //Create Nearest Filtered Texture GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST); //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); //Clean up bitmap = null; finished = true; }
public static int loadTexture(Bitmap img, int usedTexId, boolean recycle) { int[] textures = new int[1]; if(usedTexId == -1) { GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(3553, textures[0]); GLES20.glTexParameterf(3553, 10240, 9729.0F); GLES20.glTexParameterf(3553, 10241, 9729.0F); GLES20.glTexParameterf(3553, 10242, 33071.0F); GLES20.glTexParameterf(3553, 10243, 33071.0F); GLUtils.texImage2D(3553, 0, img, 0); } else { GLES20.glBindTexture(3553, usedTexId); GLUtils.texSubImage2D(3553, 0, 0, 0, img); textures[0] = usedTexId; } if(recycle) { img.recycle(); } return textures[0]; }
private void textureInThread(int textureId, MD360Program program, Bitmap bitmap) { notNull(bitmap,"bitmap can't be null!"); if (isEmpty(textureId)) return; GLES20.glActiveTexture(GLES20.GL_TEXTURE0); glCheck("MD360BitmapTexture glActiveTexture"); // Bind to the texture in OpenGL GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); glCheck("MD360BitmapTexture glBindTexture"); // Set filtering 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); // Load the bitmap into the bound texture. GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); glCheck("MD360BitmapTexture texImage2D"); GLES20.glUniform1i(program.getTextureUniformHandle(),0); glCheck("MD360BitmapTexture textureInThread"); }
private void textureInThread(int textureId, MD360Program program, Bitmap bitmap) { notNull(bitmap, "bitmap can't be null!"); if (isEmpty(textureId)) return; GLES20.glActiveTexture(GLES20.GL_TEXTURE0); glCheck("MD360BitmapTexture glActiveTexture"); // Bind to the texture in OpenGL GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId); glCheck("MD360BitmapTexture glBindTexture"); // Set filtering 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); 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); // Load the bitmap into the bound texture. GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); glCheck("MD360BitmapTexture texImage2D"); GLES20.glUniform1i(program.getTextureUniformHandle(), 0); glCheck("MD360BitmapTexture textureInThread"); }
private void textureInThread(int textureId, MD360Program program, Bitmap bitmap, int face) { notNull(bitmap, "bitmap can't be null!"); if (isEmpty(textureId)) return; GLES20.glActiveTexture(GLES20.GL_TEXTURE0); glCheck("MD360BitmapTexture glActiveTexture"); // Bind to the texture in OpenGL GLES20.glBindTexture(GLES20.GL_TEXTURE_CUBE_MAP, textureId); glCheck("MD360BitmapTexture glBindTexture"); // Set filtering GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES20.GL_TEXTURE_CUBE_MAP, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); // Load the bitmap into the bound texture. GLUtils.texImage2D(CUBE_TARGETS[face], 0, bitmap, 0); glCheck("MD360BitmapTexture texImage2D"); // Set shader texture variable to texture 0 GLES20.glUniform1i(program.getTextureUniformHandle(), 0); glCheck("MD360BitmapTexture textureInThread"); }
/** * Used by TextureManager */ int uploadTextureAndReturnId(Bitmap $bitmap, boolean $generateMipMap) /*package-private*/ { int glTextureId; int[] a = new int[1]; _gl.glGenTextures(1, a, 0); // create a 'texture name' and put it in array element 0 glTextureId = a[0]; _gl.glBindTexture(GL10.GL_TEXTURE_2D, glTextureId); if($generateMipMap && _gl instanceof GL11) { _gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } else { _gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_FALSE); } // 'upload' to gpu GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, $bitmap, 0); return glTextureId; }