List of usage examples for android.opengl GLES20 GL_TEXTURE_2D
int GL_TEXTURE_2D
To view the source code for android.opengl GLES20 GL_TEXTURE_2D.
Click Source Link
From source file:Main.java
/** * Loads the texture with the given id.// w w w.j av a 2 s.com * * @param context the application's context * @param resourceId the id of the texture * @return the texture handle */ public static int loadTexture(final Context context, final int resourceId) { final int[] textureHandle = new int[1]; if (!cachedTextureHandles.containsKey(resourceId)) { GLES20.glGenTextures(1, textureHandle, 0); if (textureHandle[0] != 0) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; // Pre scaling off final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); if (textureHandle[0] == 0) { throw new RuntimeException("Error loading texture."); } cachedTextureHandles.put(resourceId, textureHandle[0]); } } return cachedTextureHandles.get(resourceId); }
From source file:Main.java
public static int loadTexture(Bitmap bitmap) { final int[] textureHandle = new int[1]; GLES20.glGenTextures(1, textureHandle, 0); if (textureHandle[0] != 0) { // final BitmapFactory.Options options = new BitmapFactory.Options(); // options.inScaled = false; // No pre-scaling // Read in the resource // final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options); // 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_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); // Set U Wrapping GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); // Set V Wrapping // 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();/* www . j ava2 s . c o m*/ } if (textureHandle[0] == 0) { throw new RuntimeException("Error loading texture."); } return textureHandle[0]; }
From source file:Main.java
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 {// w ww .j a va 2 s . c o m 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]; }
From source file:Main.java
public static int loadTexture(final Context context, final int resourceId, int[] size) { final int texId = genTexture(); if (texId != 0) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; // No pre-scaling options.inJustDecodeBounds = true; // Just decode bounds BitmapFactory.decodeResource(context.getResources(), resourceId, options); // Set return size size[0] = options.outWidth;/*from ww w.j a va 2s.c om*/ size[1] = options.outHeight; // Decode options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options); // 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(); } return texId; }
From source file:Main.java
public static int genTexture() { return genTexture(GLES20.GL_TEXTURE_2D); }
From source file:Main.java
public static int loadTexture(final IntBuffer data, final Size size, final int usedTexId) { 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, size.width, size.height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data); } else {//from w ww. j ava 2s. c o m GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId); GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, size.width, size.height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, data); textures[0] = usedTexId; } return textures[0]; }
From source file:Main.java
public static int genTexture(int textureType) { int[] genBuf = new int[1]; GLES20.glGenTextures(1, genBuf, 0);/*w w w .j ava2 s . c o m*/ GLES20.glBindTexture(textureType, genBuf[0]); // Set texture default draw parameters if (textureType == GLES11Ext.GL_TEXTURE_EXTERNAL_OES) { GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); } else { GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); } return genBuf[0]; }
From source file:com.example.vendrisample.HelloEffects.java
License:asdf
private void loadTextures() { // Generate textures GLES20.glGenTextures(2, mTextures, 0); // Load input bitmap Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.vendri); mImageWidth = bitmap.getWidth();/*from ww w . j a v a 2 s . c o m*/ 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(); }
From source file:com.example.android.mediaeffects.MediaEffectsFragment.java
private void loadTextures() { // Generate textures GLES20.glGenTextures(2, mTextures, 0); // Load input bitmap Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.puppy); mImageWidth = bitmap.getWidth();/* w w w .j ava 2 s . co m*/ 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(); }
From source file:eu.sathra.SathraActivity.java
@SuppressLint("WrongCall") @Override//from www . j ava 2 s . c o m public void onDrawFrame(GL10 gl) { gl.glViewport(0, 0, this.getScreenWidth(), this.getScreenHeight()); // Update time variables mTimeDelta = System.currentTimeMillis() - mLastDrawTimestamp; mLastDrawTimestamp = System.currentTimeMillis(); mTime += mTimeDelta; mVirtualTimeDelta = (long) (mTimeDelta * getTimeScale()); mVirtualTime += mVirtualTimeDelta; // Setup defaults gl.glBindTexture(GL10.GL_TEXTURE_2D, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); // Clear BG float r = (float) Color.red(mParams.bgColor) / 255; float g = (float) Color.green(mParams.bgColor) / 255; float b = (float) Color.blue(mParams.bgColor) / 255; float a = (float) Color.alpha(mParams.bgColor) / 255; gl.glClearColor(r, g, b, a); gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); GLES20.glBlendEquation(GLES20.GL_FUNC_ADD); gl.glMatrixMode(GL10.GL_TEXTURE); gl.glLoadIdentity(); gl.glMatrixMode(GL10.GL_MODELVIEW); gl.glLoadIdentity(); // gl.glEnable(GL10.GL_BLEND); gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); mRootNode.onDraw(gl, mVirtualTime, mVirtualTimeDelta); // Draw lights and shadows gl.glMatrixMode(GL10.GL_TEXTURE); gl.glLoadIdentity(); gl.glScalef(1, -1, 1); // Frame Buffers are upside down gl.glMatrixMode(GL10.GL_MODELVIEW); CameraNode activeCam = CameraNode.getActiveCamera(); if (activeCam != null) { shad.setPosition(0, 0);// this.getResolutionWidth()/2, // this.getResolutionHeight()/2);//activeCam.getAbsoluteX(), // activeCam.getAbsoluteY()); } gl.glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_ONE_MINUS_SRC_ALPHA); shad.draw(gl); gl.glViewport(0, 0, this.getResolutionWidth(), this.getResolutionHeight()); // SDfDSFSDFS GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, buf[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, tex[0], 0); // Clear shadow r = (float) Color.red(mParams.ambientColor) / 255; g = (float) Color.green(mParams.ambientColor) / 255; b = (float) Color.blue(mParams.ambientColor) / 255; a = (float) Color.alpha(mParams.ambientColor) / 255; gl.glClearColor(r, g, b, a); GLES20.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); // TODO: CONCURENT MOD EXCEPTION try { Dyn4jPhysics.getInstance().getWorld().updatev(mVirtualTimeDelta * MILISECONDS_TO_SECONDS); } catch (ConcurrentModificationException e) { } // if (mIsRunning) onUpdate(mVirtualTime, mVirtualTimeDelta); // Update fps counter mFPS = 1000f / mTimeDelta; // mDebugView.postInvalidate(); // System.gc(); }