본문 바로가기

구글과인터넷/안드로이드

안드로이드 android Opengl es 2.0 다시 그리기

출처: http://gogorchg.tistory.com/entry/Android-Opengl-es-20-%EB%8B%A4%EC%8B%9C-%EA%B7%B8%EB%A6%AC%EA%B8%B0

ByteBuffer pixelBuffer;

void storePixels() {
 
try {
    GLES20
.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fbuf);
    pixelBuffer
= ByteBuffer.allocateDirect(width * height * 4).order(ByteOrder.nativeOrder());
    GLES20
.glReadPixels(0, 0, width, height, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);

    GLES20.glBindFrameBuffer(GLES20.GL_FRAMEBUFFER, 0);
    gfx
.checkGlError("store Pixels");
 
}catch (OutOfMemoryError e) {
    pixelBuffer
= null;
 
}
}

void redrawPixels() {
  GLES20
.glBindFramebuffer(GL20.GL_FRAMEBUFFER, fbuf);
 
int[] texId = new int[1];
  GLES20
.glGenTextures(1, texId, 0);
 
int bufferTex = texId[0];
  GLES20
.glBindTexture(GL20.GL_TEXTURE_2D, bufferTex);
  GLES20
.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MAG_FILTER, GL20.GL_LINEAR);
  GLES20
.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_MIN_FILTER, GL20.GL_LINEAR);
  GLES20
.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_S, repeatX ? GL20.GL_REPEAT
   
: GL20.GL_CLAMP_TO_EDGE);
  GLES20
.glTexParameterf(GL20.GL_TEXTURE_2D, GL20.GL_TEXTURE_WRAP_T, repeatY ? GL20.GL_REPEAT
   
: GL20.GL_CLAMP_TO_EDGE);
  GLES20
.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, width, height, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
  gfx
.drawTexture(bufferTex, width, height, Transform.IDENTITY, width/2, height/2, false, false, 1);
  GLES20
.glDeleteTextures(1, IntBuffer.wrap(new int[] {bufferTex}));
  pixelBuffer
= null;
  GLES20
.glBindFrameBuffer(GLES20.GL_FRAMEBUFFER, 0);
}


출처 : http://stackoverflow.com/questions/7208255/android-opengl-es-2-0-glreadpixels-and-glteximage2d-drawing-a-black-textur
 

우선 확인은 못해봤는데요.

저장해 두면 유용하게 쓸 듯해서... ㅋㅋ