''[[MobileApp>Mobile Application Guide]]'' > ''[[Android>Introduction to Android]]'' > ''Open GL''

~
~

*Open GL [#sdd36a90]
   As a superclass GL, GL10 implements the OpenGL ES 1.0~
   In the Android, contains the primary API for OpenGL ES 1.1 .

   Android NDK corresponds to OpenGL. ~
   Android NDK r3 later on, can access open gl directly.

~
~

//*描画の高速化 [#vb8aa8e7]
//
// 「2D描画で高速表示を行うにはOpenGL ESを用いるのがよく~
// 中でも『Draw Texture Extension』というOpenGLの拡張を用いるのが最速
//

*Step1:A OpenGL program painting the gray color to background [#rd338724]
***Screen [#v6c2ac74]

#ref(test02.jpg);

~
***Sample Program [#ifb129b5]

 package com.chinsanSoft;
 
 import android.app.Activity;
 import android.opengl.GLSurfaceView;
 import android.os.Bundle;
 import android.opengl.GLSurfaceView;
 import javax.microedition.khronos.egl.EGLConfig;
 import javax.microedition.khronos.opengles.GL10;
 
 public class test02 extends Activity {
    private GLSurfaceView mChinSurfaceView;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mChinSurfaceView = new GLSurfaceView(this);
        mChinSurfaceView.setRenderer(new ChinTutorial());
        setContentView(mChinSurfaceView);
    }
 }
 
 class ChinTutorial implements GLSurfaceView.Renderer {
 
   public ChinTutorial( ) {
    }
    
 
     public void onDrawFrame(GL10 gl){
    //protected void drawFrame(GL10 gl) {
 
        //Fill the background
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
    }
 
     public void onSurfaceChanged(GL10 gl, int width, int height) {
     }
 
     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
 
         //Specifies the background fill color
         gl.glClearColor(0.5f,0.5f,0.5f,1);
         
         //カラーとテクスチャ座標の補間精度 高速
         gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_FASTEST);
     }
 
 }

~
~

~


*Step2:A OpenGL programs painting a square [#rd338724]
***Screen [#webdcf85]

#ref(test03.jpg);
~
***Sample Program [#g0dee929]

 package com.chinsanSoft;
 
 // A OpenGL programs painting a square
 import android.app.Activity;
 import android.opengl.GLSurfaceView;
 import android.os.Bundle;
 import android.opengl.*;
 import java.nio.*;
 import javax.microedition.khronos.egl.EGLConfig;
 import javax.microedition.khronos.opengles.GL10;
 
 public class test03_3d extends Activity {
    private GLSurfaceView mChinSurfaceView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mChinSurfaceView = new GLSurfaceView(this);
        mChinSurfaceView.setRenderer(new ChinTutorialOne());
        setContentView(mChinSurfaceView);
    }
 }
 
 
 class ChinTutorialOne implements GLSurfaceView.Renderer {
 
    float[] square=new float[] { // vertex    
            -0.25f,-0.25f,0.0f,
             0.25f,-0.25f,0.0f,
            -0.25f, 0.25f,0.0f,
             0.25f, 0.25f,0.0f};
 
    FloatBuffer squareBuff ; // buffer of vertex
 	
 	
   public ChinTutorialOne(/*Context c*/) {
	    squareBuff=getFloatBuffer(square); // buffer of vertex
        //super(c);
    }
 
    
   	private FloatBuffer getFloatBuffer(float [] array){
 		FloatBuffer floatBuffer;
 		ByteBuffer bb = ByteBuffer.allocateDirect(array.length * 4);
 		bb.order(ByteOrder.nativeOrder());
 		floatBuffer = bb.asFloatBuffer();
 		floatBuffer.put(array);
 		floatBuffer.position(0);
 		return floatBuffer;
 	}
  
     public void onDrawFrame(GL10 gl){
    //protected void drawFrame(GL10 gl) {
 
        // Background fill
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
 
        // Specifying the modelview matrix
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        gl.glTranslatef(0,0,-1);  // Moving at parallel
        
        // Specify the color
        gl.glColor4f(1,0,0,0.5f);
        
        // Specify the vertex array
        gl.glVertexPointer(3,GL10.GL_FLOAT,0,squareBuff);
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        
        // Drawing the primitives
        gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0,4);
        
     
     }
 
     public void onSurfaceChanged(GL10 gl, int width, int height) {
     }
 
     public void onSurfaceCreated(GL10 gl, EGLConfig config) {
         //背景塗り潰し色の指定
         // Specify background fill color
         gl.glClearColor(0.5f,0.5f,0.5f,1);
         
         //カラーとテクスチャ座標の補間精度-高速
         // Color and texture coordinate interpolation accuracy - fast
         //gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,GL10.GL_FASTEST);
 
         //射影行列の指定
         // Specifying the projection matrix
         gl.glMatrixMode(GL10.GL_PROJECTION);
         gl.glLoadIdentity();
         GLU.gluOrtho2D(gl,0.0f,1.2f,0.0f,1.0f);//平行投影
         GLU.gluOrtho2D(gl,0.0f,1.2f,0.0f,1.0f); 
     }

~
~
~
*Step3:A OpenGL program that displays the cube [#l5c1c965]
***Screen [#cdde034d]

#ref(test04.jpg);
~
***Sample Program [#vfbfb687]

~
~
   Under construction

~
~
*Modeling [#beb82905]
  ポリゴン表示とテクスチャ表示ができたら、次にやりたくなるのは自分でモデリングしたオブジェクトを表示させること~
  http://ronor.blog81.fc2.com/blog-category-1.html



~
~
  ''[[Back>Introduction to Android]]''

Front page   Edit Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes