Thank you.
Main.java
Using java Syntax Highlighting
- package Syco.glex;
- import android.app.Activity;
- import android.opengl.GLSurfaceView;
- import android.os.Bundle;
- import android.view.Display;
- import android.view.Window;
- import android.view.WindowManager;
- public class Main extends Activity {
- private Display display;
- private int width;
- private int height;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- this.requestWindowFeature(Window.FEATURE_NO_TITLE);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- display=getWindowManager().getDefaultDisplay();
- width=display.getWidth();
- height=display.getHeight();
- GLSurfaceView view = new GLSurfaceView(this);
- view.setRenderer(new myRenderer(this,width,height));
- setContentView(view);
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
myRenderer.java
Using java Syntax Highlighting
- package Syco.glex;
- import android.content.Context;
- import javax.microedition.khronos.egl.EGLConfig;
- import javax.microedition.khronos.opengles.GL10;
- import android.opengl.GLU;
- import android.opengl.GLSurfaceView.Renderer;
- public class myRenderer implements Renderer {
- private Square[] square=new Square[5];
- private int[] p={-4,-2,0,2,4};
- private final Context mc;
- private final int w;
- private final int h;
- private final float ww;
- private final float hh;
- private float angolo=0;
- public myRenderer(Context mc, int w, int h) {
- this.mc=mc;
- this.w=w;
- this.h=h;
- this.ww=((float)w)/10;
- this.hh=((float)h)/10;
- for(int i=0;i<5;i++) {
- square[i]=new Square(ww,hh);
- }
- }
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- for(int i=0;i<5;i++) {
- square[i].loadGLTexture(gl, mc);
- }
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
- gl.glShadeModel(GL10.GL_SMOOTH);
- gl.glClearDepthf(1.0f);
- gl.glEnable(GL10.GL_DEPTH_TEST);
- gl.glDepthFunc(GL10.GL_LEQUAL);
- gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
- }
- public void onDrawFrame(GL10 gl) {
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glLoadIdentity();
- for(int i=0;i<5;i++) {
- gl.glPushMatrix();
- gl.glTranslatef((float)(p[i]*ww),(float)(4*hh),-600.0f);
- gl.glRotatef(angolo, 0.0f, 1.0f, 0.0f);
- square[i].draw(gl);
- gl.glPopMatrix();
- }
- angolo+=2;
- angolo%=360;
- }
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL10.GL_PROJECTION);
- GLU.gluPerspective(gl, 45.0f, (float)width/(float)height, 1.0f, 700.0f);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity();
- }
- }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4
Square.java
Using java Syntax Highlighting
- package Syco.glex;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.opengl.GLUtils;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import java.nio.FloatBuffer;
- import java.nio.ShortBuffer;
- import javax.microedition.khronos.opengles.GL10;
- public class Square {
- private float[] vertices;
- private float[] texture;
- private int[] textures=new int[2];
- private short[] indices = {0, 1, 2, 0, 2, 3,
- 0, 2, 1, 0, 3, 2 };
- private FloatBuffer vertexBuffer;
- private ShortBuffer indexBuffer;
- private FloatBuffer textureBuffer;
- public Square(float w, float h) {
- vertices=new float[]{
- -w, h, 0.0f, // t l
- -w, -h, 0.0f, // b l
- w, -h, 0.0f, // b r
- w, h, 0.0f // t r
- };
- texture=new float[] {
- 1.0f, 0.0f, // b r
- 1.0f, 1.0f, // t r
- 0.0f, 1.0f, // t l
- 0.0f, 0.0f, // b l
- 0.0f, 0.0f, // b l
- 0.0f, 1.0f, // t l
- 1.0f, 1.0f, // t r
- 1.0f, 0.0f, // b r
- };
- ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
- vbb.order(ByteOrder.nativeOrder());
- vertexBuffer = vbb.asFloatBuffer();
- vertexBuffer.put(vertices);
- vertexBuffer.position(0);
- vbb = ByteBuffer.allocateDirect(texture.length * 4);
- vbb.order(ByteOrder.nativeOrder());
- textureBuffer = vbb.asFloatBuffer();
- textureBuffer.put(texture);
- textureBuffer.position(0);
- vbb = ByteBuffer.allocateDirect(indices.length * 2);
- vbb.order(ByteOrder.nativeOrder());
- indexBuffer = vbb.asShortBuffer();
- indexBuffer.put(indices);
- indexBuffer.position(0);
- }
- public void draw(GL10 gl) {
- gl.glEnable(GL10.GL_CULL_FACE);
- gl.glCullFace(GL10.GL_BACK);
- gl.glFrontFace(GL10.GL_CCW);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
- gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
- gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- gl.glDisable(GL10.GL_CULL_FACE);
- }
- public void loadGLTexture(GL10 gl, Context context) {
- gl.glGenTextures(2, textures, 0);
- gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
- Bitmap bitmap1=BitmapFactory.decodeResource(context.getResources(), R.drawable.front);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap1, 0);
- bitmap1.recycle();
- gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
- gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
- Bitmap bitmap2=BitmapFactory.decodeResource(context.getResources(), R.drawable.back);
- GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap2, 0);
- bitmap2.recycle();
- }
- }
Parsed in 0.048 seconds, using GeSHi 1.0.8.4


