Created
October 2, 2015 08:54
-
-
Save hisui/433e09e899175844cfc4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.opengl.GLES20; | |
import android.view.Surface; | |
import javax.microedition.khronos.egl.EGL10; | |
import javax.microedition.khronos.egl.EGLConfig; | |
import javax.microedition.khronos.egl.EGLContext; | |
import javax.microedition.khronos.egl.EGLDisplay; | |
import javax.microedition.khronos.egl.EGLSurface; | |
public class SurfaceUtil { | |
private static final int[] ATTRIB_LIST = new int[] { | |
EGL10.EGL_RED_SIZE, 8, | |
EGL10.EGL_GREEN_SIZE, 8, | |
EGL10.EGL_BLUE_SIZE, 8, | |
EGL10.EGL_ALPHA_SIZE, 8, | |
EGL10.EGL_NONE, | |
}; | |
// http://stackoverflow.com/a/21564236/2681195 | |
public static void clear(Surface dest) { | |
EGL10 egl = (EGL10) EGLContext.getEGL(); | |
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); | |
int[] version = new int[2]; | |
egl.eglInitialize(display, version); | |
EGLConfig[] configs = new EGLConfig[1]; | |
int[] numConfig = new int[1]; | |
egl.eglChooseConfig(display, ATTRIB_LIST, configs, 1, numConfig); | |
EGLSurface surface = egl.eglCreateWindowSurface(display, configs[0], dest, null); | |
EGLContext context = egl.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, null); | |
egl.eglMakeCurrent(display, surface, surface, context); | |
GLES20.glClearColor(0, 0, 0, 0); | |
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | |
egl.eglSwapBuffers(display, surface); | |
egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT); | |
egl.eglDestroyContext(display, context); | |
egl.eglDestroySurface(display, surface); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not sure, but you may need
egl.eglTerminate(display)
?