//메뉴바 없는 풀스크린
//AndroidMainifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<activity android:name=".MyActivity" android:label="leesunho Activity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> </intent-filter> </activity>
</application>
//myactivity.xml
<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <TableRow> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="안드로이드 화면 분활 \n화면의 일부영역에 OpenGL ES 화면 넣기입니다." android:id="@+id/time" /> </TableRow> <TableRow> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon" android:scaleType="center" /> <android.opengl.GLSurfaceView android:id="@+id/surface_view" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
</TableRow>
</TableLayout>
//
package kr.mobileplace.lecture; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.FloatBuffer; import javax.microedition.khronos.egl.EGLConfig; import javax.microedition.khronos.opengles.GL10;
import android.app.Activity; import android.opengl.GLSurfaceView; import android.os.Bundle; import android.view.View; import android.view.ViewGroup.LayoutParams;
public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* 안드로이드 화면 분활 화면의 일부영역에 OpenGL ES 화면 넣기입니다. setContentView(R.layout.myactivity); GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.surface_view); glSurfaceView.setRenderer(new ClearRenderer()); //glSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888); */ //Opengl ES화면 위로 안드로이드 레이아웃 화면 오버레이 GLSurfaceView glSurfaceView = new GLSurfaceView(this); glSurfaceView.setRenderer(new ClearRenderer()); setContentView(glSurfaceView); View v = getLayoutInflater().inflate(R.layout.myactivity, null); this.addContentView(v, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); } }
class ClearRenderer implements GLSurfaceView.Renderer { //class ClearRenderer extends GLSurfaceView implements Renderer { float[] triangle = new float[] { -0.5f, 0, 0, 0, 0.5f, 0, 0.5f, 0, 0 }; FloatBuffer triangleVB; public ClearRenderer() {
triangleVB = createFloatBuffer(triangle); } @Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); gl.glColor4f(1, 0, 0, 0.5f); gl.glVertexPointer(3, GL10.GL_FLOAT, 0, triangleVB); gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3); }
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); }
@Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); gl.glMatrixMode(GL10.GL_PROJECTION); gl.glLoadIdentity(); //GLU.gluOrtho2D(gl, -1.0f, 1.0f, -1.0f, 1.0f); } protected FloatBuffer createFloatBuffer(float[] array) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length << 2); byteBuffer.order(ByteOrder.nativeOrder()); FloatBuffer floatBuffer = byteBuffer.asFloatBuffer(); floatBuffer.put(array); floatBuffer.position(0); return floatBuffer; } } |