Java Code Examples for android.opengl.GLES20#glTexParameteri()
The following examples show how to use
android.opengl.GLES20#glTexParameteri() .
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: CameraFBORender.java From AudioVideoCodec with Apache License 2.0 | 6 votes |
/** * 创建摄像头预览扩展纹理 */ private void createCameraTexture() { int[] textureIds = new int[1]; GLES20.glGenTextures(1, textureIds, 0); cameraTextureId = textureIds[0]; GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, cameraTextureId); //环绕(超出纹理坐标范围) (s==x t==y GL_REPEAT 重复) GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); //过滤(纹理像素映射到坐标点) (缩小、放大:GL_LINEAR线性) GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); surfaceTexture = new SurfaceTexture(cameraTextureId); surfaceTexture.setOnFrameAvailableListener(this); if (onSurfaceListener != null) { //回调给CameraManager获取surfaceTexture:通过camera.setPreviewTexture(surfaceTexture); onSurfaceListener.onSurfaceCreate(surfaceTexture, fboTextureId); } // 解绑扩展纹理 GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); }
Example 2
Source File: MD360VideoTexture.java From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 | 6 votes |
@Override protected int createTextureId() { int[] textures = new int[1]; // Generate the texture to where android view will be rendered GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glGenTextures(1, textures, 0); glCheck("Texture generate"); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]); glCheck("Texture bind"); 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); return textures[0]; }
Example 3
Source File: Texture2dProgram.java From RtmpPublisher with Apache License 2.0 | 6 votes |
/** * Creates a texture object suitable for use with this program. * <p> * On exit, the texture will be bound. */ public int createTextureObject() { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); GlUtil.checkGlError("glGenTextures"); int texId = textures[0]; GLES20.glBindTexture(mTextureTarget, texId); GlUtil.checkGlError("glBindTexture " + texId); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); 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); GlUtil.checkGlError("glTexParameter"); return texId; }
Example 4
Source File: GlUtil.java From sealrtc-android with MIT License | 6 votes |
/** * Creates a texture object suitable for use with this program. * * <p>On exit, the texture will be bound. */ public static int createTextureObject(int textureTarget) { int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); GlUtil.checkGlError("glGenTextures"); int texId = textures[0]; GLES20.glBindTexture(textureTarget, texId); GlUtil.checkGlError("glBindTexture " + texId); GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GlUtil.checkGlError("glTexParameter"); return texId; }
Example 5
Source File: GLRenderer.java From HoloKilo with GNU General Public License v3.0 | 6 votes |
public static int createCameraTexture() { int[] texture = new int[1]; GLES20.glGenTextures(1,texture, 0); // External texture so that camera image is directly // fed in GPU. Needs a GLES1.1 extention. GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texture[0]); 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); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0); return texture[0]; }
Example 6
Source File: Texture.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public int texture() { if (texture != 0) { return texture; } if (bitmap.isRecycled()) { return 0; } int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); texture = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture); 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); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); int width = bitmap.getWidth(); int height = bitmap.getHeight(); int[] pixels = new int[width * height]; bitmap.getPixels(pixels, 0, width, 0, 0, width, height); for (int i = 0; i < pixels.length; i += 1) { int argb = pixels[i]; pixels[i] = argb & 0xff00ff00 | ((argb & 0xff) << 16) | ((argb >> 16) & 0xff); } GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, IntBuffer.wrap(pixels)); int px = bitmap.getPixel(0, 0); ByteBuffer buffer = ByteBuffer.allocateDirect(4); //fix for android 9.0 buffer.putInt(px).position(0); GLES20.glTexSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, 1, 1, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, buffer); Utils.HasGLError(); return texture; }
Example 7
Source File: CameraGLRendererBase.java From FaceT with Mozilla Public License 2.0 | 5 votes |
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 8
Source File: CameraGLRendererBase.java From react-native-documentscanner-android with MIT License | 5 votes |
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 9
Source File: GLUtil.java From react-native-3d-model-view with MIT License | 5 votes |
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 10
Source File: GlToneCurveFilter.java From SimpleVideoEdit with Apache License 2.0 | 5 votes |
@Override public void setup() { super.setup();// 1 GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[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.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); while (!runOnDraw.isEmpty()) { runOnDraw.removeFirst().run(); } }
Example 11
Source File: BayerShader.java From retroboy with MIT License | 5 votes |
public BayerShader(ShaderProgram program, Camera.Size previewSize) { _program = program; // Find handles to shader parameters _thresholdTextureLocation = _program.getUniformLocation("sThreshold"); _targetSizeLocation = _program.getUniformLocation("uTargetSize"); // Scale the preview frames to match TARGET_WIDTH _targetSize = new int[] {TARGET_WIDTH, (int)((float)TARGET_WIDTH * ((float)previewSize.height / previewSize.width))}; // Bind the Bayer threshold matrix as a texture int[] textures = new int[1]; GLES20.glGenTextures(textures.length, textures, 0); _thresholdTextureHandle = textures[0]; GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, _thresholdTextureHandle); checkGlError("glBindTexture"); 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); 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); GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE, _targetSize[0], _targetSize[1], 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, createScaledTexture(_bayerThresholdMatrix, 8, 8, _targetSize[0], _targetSize[1])); checkGlError("glTexImage2D"); }
Example 12
Source File: GlUtil.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
/** * Creates a texture from raw data. * * @param data Image data, in a "direct" ByteBuffer. * @param width Texture width, in pixels (not bytes). * @param height Texture height, in pixels. * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA). * @return Handle to texture. */ public static int createImageTexture(ByteBuffer data, int width, int height, int format) { 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. GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, /*level*/ 0, format, width, height, /*border*/ 0, format, GLES20.GL_UNSIGNED_BYTE, data); GlUtil.checkGlError("loadImageTexture"); return textureHandle; }
Example 13
Source File: OpenGlUtils.java From TikTok with Apache License 2.0 | 5 votes |
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 14
Source File: CameraGLRendererBase.java From real_time_circle_detection_android with MIT License | 5 votes |
private void initFBO(int width, int height) { Log.d(LOGTAG, "initFBO("+width+"x"+height+")"); deleteFBO(); GLES20.glGenTextures(1, texDraw, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texDraw[0]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); 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); 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.glGenTextures(1, texFBO, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texFBO[0]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); 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); 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); //int hFBO; GLES20.glGenFramebuffers(1, FBO, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, FBO[0]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texFBO[0], 0); Log.d(LOGTAG, "initFBO error status: " + GLES20.glGetError()); int FBOstatus = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); if (FBOstatus != GLES20.GL_FRAMEBUFFER_COMPLETE) Log.e(LOGTAG, "initFBO failed, status: " + FBOstatus); mFBOWidth = width; mFBOHeight = height; }
Example 15
Source File: CameraGLRendererBase.java From VIA-AI with MIT License | 5 votes |
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 16
Source File: CameraSurfaceView.java From Paddle-Lite-Demo with Apache License 2.0 | 5 votes |
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { // Create OES texture for storing camera preview data(YUV format) GLES20.glGenTextures(1, camTextureId, 0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, camTextureId[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); surfaceTexture = new SurfaceTexture(camTextureId[0]); surfaceTexture.setOnFrameAvailableListener(this); // Prepare vertex and texture coordinates int bytes = vertexCoords.length * Float.SIZE / Byte.SIZE; vertexCoordsBuffer = ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).asFloatBuffer(); textureCoordsBuffer = ByteBuffer.allocateDirect(bytes).order(ByteOrder.nativeOrder()).asFloatBuffer(); vertexCoordsBuffer.put(vertexCoords).position(0); textureCoordsBuffer.put(textureCoords).position(0); // Create vertex and fragment shaders // camTextureId->fboTexureId progCam2FBO = Utils.createShaderProgram(vss, fssCam2FBO); vcCam2FBO = GLES20.glGetAttribLocation(progCam2FBO, "vPosition"); tcCam2FBO = GLES20.glGetAttribLocation(progCam2FBO, "vTexCoord"); GLES20.glEnableVertexAttribArray(vcCam2FBO); GLES20.glEnableVertexAttribArray(tcCam2FBO); // fboTexureId/drawTexureId -> screen progTex2Screen = Utils.createShaderProgram(vss, fssTex2Screen); vcTex2Screen = GLES20.glGetAttribLocation(progTex2Screen, "vPosition"); tcTex2Screen = GLES20.glGetAttribLocation(progTex2Screen, "vTexCoord"); GLES20.glEnableVertexAttribArray(vcTex2Screen); GLES20.glEnableVertexAttribArray(tcTex2Screen); }
Example 17
Source File: FileTextureSource.java From Tanks with MIT License | 4 votes |
private int loadTexture() { ResultRunnable<Integer> runnable = new ResultRunnable<Integer>() { @Override protected Integer onRun() { try { String fileName = getTextureFileName(name); InputStream stream = GameContext.context.getAssets().open(fileName); Bitmap bitmap = BitmapFactory.decodeStream(stream); stream.close(); int type = GLUtils.getType(bitmap); int format = GLUtils.getInternalFormat(bitmap); int error; int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, format, bitmap, type, 0); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error); 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.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); if (generateMipmap) { GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D); if ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) throw new GLException(error, Integer.toString(error)); } bitmap.recycle(); return textures[0]; } catch(Exception e) { throw new RuntimeException(e); } } }; GameContext.glThread.sendEvent(runnable); return runnable.getResult(); }
Example 18
Source File: TextureRender.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/** * Initializes GL state. Call this after the EGL surface has been created and made current. */ void surfaceCreated() throws TranscodingException { mProgram = createProgram(VERTEX_SHADER, FRAGMENT_SHADER); if (mProgram == 0) { throw new TranscodingException("failed creating program"); } maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition"); checkGlError("glGetAttribLocation aPosition"); if (maPositionHandle == -1) { throw new TranscodingException("Could not get attrib location for aPosition"); } maTextureHandle = GLES20.glGetAttribLocation(mProgram, "aTextureCoord"); checkGlError("glGetAttribLocation aTextureCoord"); if (maTextureHandle == -1) { throw new TranscodingException("Could not get attrib location for aTextureCoord"); } muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); checkGlError("glGetUniformLocation uMVPMatrix"); if (muMVPMatrixHandle == -1) { throw new TranscodingException("Could not get attrib location for uMVPMatrix"); } muSTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uSTMatrix"); checkGlError("glGetUniformLocation uSTMatrix"); if (muSTMatrixHandle == -1) { throw new TranscodingException("Could not get attrib location for uSTMatrix"); } int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); mTextureID = textures[0]; GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID); checkGlError("glBindTexture mTextureID"); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); 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); checkGlError("glTexParameter"); }
Example 19
Source File: GLTextureOutputRenderer.java From UltimateAndroid with Apache License 2.0 | votes |
private void initFBO() { if(frameBuffer != null) { GLES20.glDeleteFramebuffers(1, frameBuffer, 0); frameBuffer = null; } if(texture_out != null) { GLES20.glDeleteTextures(1, texture_out, 0); texture_out = null; } if(depthRenderBuffer != null) { GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0); depthRenderBuffer = null; } frameBuffer = new int[1]; texture_out = new int[1]; depthRenderBuffer = new int[1]; GLES20.glGenFramebuffers(1, frameBuffer, 0); GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0); GLES20.glGenTextures(1, texture_out, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null); 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); 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.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0); GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]); GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight()); GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]); int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER); if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError()); } }
Example 20
Source File: CameraPreviewInput.java From UltimateAndroid with Apache License 2.0 | votes |
@Override protected void initWithGLContext() { super.initWithGLContext(); int[] textures = new int[1]; GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textures[0]); 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); texture_in = textures[0]; camTex = new SurfaceTexture(texture_in); camTex.setOnFrameAvailableListener(this); boolean failed = true; while(failed) { try { if(camera != null) { camera.stopPreview(); camera.release(); camera = null; } camera = createCamera(); camera.setPreviewTexture(camTex); camera.startPreview(); setRenderSizeToCameraSize(); failed = false; } catch (Exception e) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); Log.e("CameraInput", sw.toString()); if(camera != null) { camera.release(); camera = null; } } } }