All About Android-Sample Code for Open GL in Android-ANDROIDKAWE - Welcome to ANDROID KAWE, Ini adalah sebuah blog directory tentang burung,baik itu suara burung ataupun tips perawatan burung.Blog ini adalah situs perangkum otomatis dari pencarian google yang kali ini berjudul All About Android-Sample Code for Open GL in Android-ANDROIDKAWE.Ada ribuan artikel yang sudah terekam ke dalam situs ini,silahkan cari sesuai yang kalian kehendaki,untuk artikel selanjutnya tentang judul diatas bisa kalian baca di bawah ini.
Konten : All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
Judul : All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
Now your basic Open GL ES concepts are clear as written in the previous post (http://creativeandroidapps.blogspot.in/2012/07/basics-of-opengl-in-android.html) you are ready to create something with OpenGL on Android in your creative application.
This post is explaining a very popular sample for the Open GL for the new developers to quickly understand the implementation of Open GL functions and classes. For a basic Open GL project you need to create a activity class where you host your GLSurfaceView. The render something on the view we need to implement the GLSurfaceView.Renderer interface.
See here the code of my sample class.
Create a Activity Class
See the highlighted code which you need to add in your activity class after implementing the following two classes.
Now create a class named MyGLSurfaceView which extends the GLSurfaceView to set as the view of activity.
See the implementation of the Renderer which will render the color.
Now you can run the sample code and see the following result as your first sample of Open GL on android.
On touch you will see a color change on the Open GL surface view created in activity.
If you like the post please provide your feedback.
Thanks
Creative Android Apps
Anda sedang membaca artikel All About Android-Sample Code for Open GL in Android-ANDROIDKAWE dan artikel ini url permalinknya adalah https://androidkawe.blogspot.com/2012/07/all-about-android-sample-code-for-open.html Semoga artikel ini bisa bermanfaat.Sekali lagi,ini adalah situs auto yang tidak ditulis langsung oleh admin,Kami tidak menjamin akan kebenaran dari artikel yang tertulis.
Konten : All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
Judul : All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
Sample Code for Open GL in Android
Now your basic Open GL ES concepts are clear as written in the previous post (http://creativeandroidapps.blogspot.in/2012/07/basics-of-opengl-in-android.html) you are ready to create something with OpenGL on Android in your creative application.
This post is explaining a very popular sample for the Open GL for the new developers to quickly understand the implementation of Open GL functions and classes. For a basic Open GL project you need to create a activity class where you host your GLSurfaceView. The render something on the view we need to implement the GLSurfaceView.Renderer interface.
See here the code of my sample class.
Create a Activity Class
package com.example.sampleopengl;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
private MyGLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new MyGLSurfaceView(this,null);
setContentView(mGLView);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
See the highlighted code which you need to add in your activity class after implementing the following two classes.
Now create a class named MyGLSurfaceView which extends the GLSurfaceView to set as the view of activity.
package com.example.sampleopengl;
import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class MyGLSurfaceView extends GLSurfaceView {
MyGLRenderer mRenderer;
public MyGLSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
mRenderer = new MyGLRenderer();
setRenderer(mRenderer);
}
//change the color on touch
public boolean onTouchEvent(final MotionEvent event) {
queueEvent(new Runnable(){
public void run() {
mRenderer.setColor(event.getX() / getWidth(),
event.getY() / getHeight(), 1.0f);
}});
return true;
}
}
See the implementation of the Renderer which will render the color.
package com.example.sampleopengl;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLSurfaceView;
public class MyGLRenderer implements GLSurfaceView.Renderer {
private float mRed;
private float mGreen;
private float mBlue;
public void setColor(float r, float g, float b) {
mRed = r;
mGreen = g;
mBlue = b;
}
@Override //function draw the opengl graphics
public void onDrawFrame(GL10 gl) {
// TODO Auto-generated method stub
gl.glClearColor(mRed, mGreen, mBlue, 1.0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
// TODO Auto-generated method stub
gl.glViewport(0, 0, w, h);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig arg1) {
// TODO Auto-generated method stub
}
}
Now you can run the sample code and see the following result as your first sample of Open GL on android.
Open GL - Color 1 |
On touch you will see a color change on the Open GL surface view created in activity.
Open GL - Color 2 |
If you like the post please provide your feedback.
Thanks
Creative Android Apps
Demikianlah Artikel All About Android-Sample Code for Open GL in Android-ANDROIDKAWE
Semoga artikel tentang All About Android-Sample Code for Open GL in Android-ANDROIDKAWE, mudah-mudahan bisa memberi manfaat untuk anda semua.
Anda sedang membaca artikel All About Android-Sample Code for Open GL in Android-ANDROIDKAWE dan artikel ini url permalinknya adalah https://androidkawe.blogspot.com/2012/07/all-about-android-sample-code-for-open.html Semoga artikel ini bisa bermanfaat.Sekali lagi,ini adalah situs auto yang tidak ditulis langsung oleh admin,Kami tidak menjamin akan kebenaran dari artikel yang tertulis.
Tag :
Android OpenGL