'Android'에 해당되는 글 33건
- 2009.08.14 [Android] 지도에 Path 그리기 확인
- 2009.08.11 [Android] OpenGL 로 원하는 도형 만들기 1
- 2009.07.26 [Android] Camera와 OpenGL 동시에 표시하기 14
class Cube
{
public Cube()
{
int one = 0x10000;
int vertices[] = {
//x, y, z,
-one, -one, -one, // index #0
one, -one, -one, // index #1
one, one, -one, // index #2
-one, one, -one, // index #3
-one, -one, one, // index #4
one, -one, one, // index #5
one, one, one, // index #6
-one, one, one, // index #7
};
int colors[] = {
//R, G, B, A
0, 0, 0, one,
one, 0, 0, one,
one, one, 0, one,
0, one, 0, one,
0, 0, one, one,
one, 0, one, one,
one, one, one, one,
0, one, one, one,
};
byte indices[] = {
// Triangle 로 쪼개는 인덱스 번호들
0, 4, 5, 0, 5, 1,
1, 5, 6, 1, 6, 2,
2, 6, 7, 2, 7, 3,
3, 7, 4, 3, 4, 0,
4, 7, 6, 4, 6, 5,
3, 0, 1, 3, 1, 2,
};
// Buffers to be passed to gl*Pointer() functions
// must be direct, i.e., they must be placed on the
// native heap where the garbage collector cannot
// move them.
//
// Buffers with multi-byte datatypes (e.g., short, int, float)
// must have their byte order set to native order
ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
vbb.order(ByteOrder.nativeOrder());
mVertexBuffer = vbb.asIntBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
cbb.order(ByteOrder.nativeOrder());
mColorBuffer = cbb.asIntBuffer();
mColorBuffer.put(colors);
mColorBuffer.position(0);
mIndexBuffer = ByteBuffer.allocateDirect(indices.length);
mIndexBuffer.put(indices);
mIndexBuffer.position(0);
}
public void draw(GL10 gl)
{
gl.glFrontFace(gl.GL_CW);
gl.glVertexPointer(3, gl.GL_FIXED, 0, mVertexBuffer);
gl.glColorPointer(4, gl.GL_FIXED, 0, mColorBuffer);
gl.glDrawElements(gl.GL_TRIANGLES, 36, gl.GL_UNSIGNED_BYTE, mIndexBuffer);
}
private IntBuffer mVertexBuffer;
private IntBuffer mColorBuffer;
private ByteBuffer mIndexBuffer;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Preview mPreview = new Preview(this);
mRenderer = new CubeRenderer(true);
mGLSurfaceView = new GLSurfaceView(this);
//translucent
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mGLSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
mGLSurfaceView.setRenderer(mRenderer);
//OpenGL 먼저 표시하기
setContentView(mGLSurfaceView);
//그 다음 카메라 표시하기
addContentView(mPreview, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
private GLSurfaceView mGLSurfaceView;
private CubeRenderer mRenderer;
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
}
//////////////////////////////
// camer preview
////////////////////////////
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
boolean mPreviewRunning = false;
Preview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera c) {
mCamera.startPreview();
}
};
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
try{
mCamera.setPreviewDisplay(holder);
if (false) throw new IOException();
}catch (IOException e){
//do something
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mPreviewRunning = false;//// added
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mPreviewRunning) { ///added
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
//
try{
mCamera.setPreviewDisplay(holder);
if (false) throw new IOException();
}catch (IOException e){
//do something
}
mCamera.startPreview();
mPreviewRunning = true; ///added
}
}