336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
1.0에서는 Texture에 Bitmap 파일만 넣어주면, Android에서 알아서 바꿔주었었다.
아주 간편하게 Texture를 적용 시킬 수가 있었습니다.
(안에서 어떻게 돌아가든 관계 없어..)
하지만, 2.0에서는 모든 것을 개발자에게 맡기게 되어있죠.
구글링을 해본 결과 , 안드로이드의 Bitmap 값은 ARGB로 32bit 픽셀로 되어 있다고 합니다.
하지만, Opengl은 RGBA로 되어 있어서 컨버팅 할 필요가 생긴거죠.
그래서 2.0에서는 glTexture2D 의 매개변수가 Buffer로 되어 있는 겁니다.
결과적으로 Texture에 Bitmap을 로드 시킬 때 다음과 같은 코드 형식으로 하면 되겠네요.
private static int loadTexture(InputStream is) { int[] textureId = new int[1]; Bitmap bitmap; bitmap = BitmapFactory.decodeStream(is); ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bitmap.getWidth() * bitmap.getHeight() * 4); byteBuffer.order(ByteOrder.BIG_ENDIAN); IntBuffer ib = byteBuffer.asIntBuffer(); int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()]; bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); for(int i=0; i<pixels.length; i++){ ib.put(pixels[i] << 8 | pixels[i] >>> 24); } bitmap.recycle(); byteBuffer.position(0); GLES20.glGenTextures ( 1, textureId, 0 ); GLES20.glBindTexture ( GLES20.GL_TEXTURE_2D, textureId[0] ); GLES20.glTexImage2D ( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, bitmap.getWidth(), bitmap.getHeight(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, byteBuffer ); 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 ); return textureId[0]; }
'나의 플랫폼 > 안드로이드' 카테고리의 다른 글
[ Android ] 타이틀 바 높이 확인 방법 (0) | 2011.10.13 |
---|---|
[ Android Opengl es ] 화면이 하얗게 보이는 현상. (3) | 2011.10.12 |
[ Android Opengl es 2.0 ] glDrawArrays 와 glDrawElements 사용법 (4) | 2011.10.07 |
[Android Opengl es 2.0 ] VBO(VertexArray Buffer Object ) 관련해서 (0) | 2011.10.07 |
[ Android Opengl es 2.0 ] Vertex배열을 이용하여 간단한 도형 만들기 (0) | 2011.10.06 |