MobileApp > Android > Open GL



Open GL

縲縲縲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.



Step1シ哂 OpenGL program painting the gray color to background

Screen

test02.jpg


Sample Program

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シ哂 OpenGL programs painting a square

Screen

test03.jpg


Sample Program

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); 
    }




Step3シ哂 OpenGL program that displays the cube

Screen

test04.jpg


Sample Program



縲縲縲Under construction



Modeling

縲縲繝昴Μ繧エ繝ウ陦ィ遉コ縺ィ繝繧ッ繧ケ繝√Ε陦ィ遉コ縺後〒縺阪◆繧峨∵ャ。縺ォ繧繧翫◆縺上↑繧九ョ縺ッ閾ェ蛻縺ァ繝「繝繝ェ繝ウ繧ー縺励◆繧ェ繝悶ず繧ァ繧ッ繝医r陦ィ遉コ縺輔○繧九%縺ィ
縲縲http://ronor.blog81.fc2.com/blog-category-1.html



縲縲Back

     




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