2013년 8월 16일 금요일

Hello OpenGL











GLSurfaceView 를 상속받아 View 를 만드는 일.


GLSurfaceView.Renderer 를 상속받아 renderer 를 만드는 일.






--------------------------------------------------------------



import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

private GLSurfaceView mGLView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);       
        
        //setContentView(R.layout.activity_main);
        
        
        // Create a GLSurfaceView instance and set it
        // as the ContentView for this Activity.
        
        mGLView = new MyGLSurfaceView(this);
        setContentView( mGLView);        
        
    }
    

    @Override
    protected void onPause() {
   
        super.onPause();
        
        // The following call pauses the rendering thread.
        // If your OpenGL application is memory intensive,
        // you should consider de-allocating objects that
        // consume significant memory here.
        mGLView.onPause();
    }
    
    @Override
    protected void onResume() {
   
        super.onResume();
        
        // The following call resumes a paused rendering thread.
        // If you de-allocated graphic objects for onPause()
        // this is a good place to re-allocate them.
        mGLView.onResume();
    }    


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        // getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
}




--------------------------------------------------------------






import android.content.Context;
import android.opengl.GLSurfaceView;


public class MyGLSurfaceView extends GLSurfaceView {

public MyGLSurfaceView(Context context) {

super(context);
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2);

// Set the Renderer for drawing on the GLSurfaceView
setRenderer( new MyRenderer());
// Render the view only when there is a change in the drawing data
setRenderMode( GLSurfaceView.RENDERMODE_WHEN_DIRTY);

}


}


--------------------------------------------------------------



import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

public class MyRenderer implements GLSurfaceView.Renderer {

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// Set the background frame color
GLES20.glClearColor( 1.0f, 0.0f, 0.0f, 1.0f);
}
@Override
public void onDrawFrame(GL10 gl) {
// Redraw background color
GLES20.glClear( GLES20.GL_COLOR_BUFFER_BIT );
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

GLES20.glViewport( 0, 0, width, height);
}


}



















댓글 없음:

댓글 쓰기

Eclipse hangs at the Android SDK Content Loader

eclipse -clean