Advertisement
Guest User

Untitled

a guest
Aug 9th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1. package com.androidgames.gl3d.tests;
  2.  
  3. import javax.microedition.khronos.opengles.GL10;
  4.  
  5. import android.opengl.GLU;
  6.  
  7. import com.androidgames.framework.Game;
  8. import com.androidgames.framework.Screen;
  9. import com.androidgames.framework.gl.Texture;
  10. import com.androidgames.framework.gl.Vertices3;
  11. import com.androidgames.framework.impl.GLGame;
  12. import com.androidgames.framework.impl.GLScreen;
  13.  
  14. public class CubeTest extends GLGame {
  15.    
  16.     public Screen getStartScreen() {
  17.         return new CubeScreen(this);
  18.     }
  19.    
  20.     class CubeScreen extends GLScreen {
  21.        
  22.         Vertices3 cube;
  23.         Texture texture;
  24.         float angle = 0;
  25.  
  26.         public CubeScreen(Game game) {
  27.             super(game);
  28.             cube = createCube();
  29.             texture = new Texture(glGame, "sprites.png");
  30.         }
  31.        
  32.         private Vertices3 createCube() {
  33.             float[] vertices = {
  34.                 -0.5F, -0.5F, 0.5F,    0.5F, 1,
  35.                  0.5F, -0.5F, 0.5F,    1,    1,
  36.                  0.5F,  0.5F, 0.5F,    1,    0.5F,
  37.                 -0.5F,  0.5F, 0.5F,    0.5F, 0.5F,
  38.                
  39.                 0.5F, -0.5F,  0.5F,    0.5F, 1,
  40.                 0.5F, -0.5F, -0.5F,    1,    1,
  41.                 0.5F,  0.5F, -0.5F,    1,    0.5F,
  42.                 0.5F,  0.5F,  0.5F,    0.5F, 0.5F,
  43.                
  44.                  0.5F, -0.5F, -0.5F,    0.5F, 1,
  45.                 -0.5F, -0.5F, -0.5F,    1,    1,
  46.                 -0.5F,  0.5F, -0.5F,    1,    0.5F,
  47.                  0.5F,  0.5F, -0.5F,    0.5F, 0.5F,
  48.                
  49.                 -0.5F, -0.5F, -0.5F,    0.5F, 1,
  50.                 -0.5F, -0.5F,  0.5F,    1,    1,
  51.                 -0.5F,  0.5F,  0.5F,    1,    0.5F,
  52.                 -0.5F,  0.5F, -0.5F,    0.5F, 0.5F,
  53.                
  54.                 -0.5F, 0.5F,  0.5F,    0.5F, 1,
  55.                  0.5F, 0.5F,  0.5F,    1,    1,
  56.                  0.5F, 0.5F, -0.5F,    1,    0.5F,
  57.                 -0.5F, 0.5F, -0.5F,    0.5F, 0.5F,
  58.                
  59.                 -0.5F, -0.5F,  0.5F,    0.5F, 1,
  60.                  0.5F, -0.5F,  0.5F,    1,    1,
  61.                  0.5F, -0.5F, -0.5F,    1,    0.5F,
  62.                 -0.5F, -0.5F, -0.5F,    0.5F, 0.5F
  63.             };
  64.            
  65.             short[] indices = {
  66.                 0,   1,  3, 1,   2,  3,
  67.                 4,   5,  7, 5,   6,  7,
  68.                 8,   9, 11, 9,  10, 11,
  69.                 12, 13, 15, 13, 14, 15,
  70.                 16, 17, 19, 17, 18, 19,
  71.                 20, 21, 23, 21, 22, 21
  72.             };
  73.            
  74.             Vertices3 cube = new Vertices3(glGraphics, 24, 36, false, true);
  75.             cube.setVertices(vertices, 0, vertices.length);
  76.             cube.setIndices(indices, 0, indices.length);
  77.            
  78.             return cube;
  79.         }
  80.  
  81.         @Override
  82.         public void update(float deltaTime) {
  83.             angle += 45 * deltaTime;
  84.         }
  85.  
  86.         @Override
  87.         public void present(float deltaTime) {
  88.             GL10 gl = glGraphics.getGL();
  89.            
  90.             gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
  91.             gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  92.            
  93.             gl.glMatrixMode(GL10.GL_PROJECTION);
  94.             gl.glLoadIdentity();
  95.             GLU.gluPerspective(gl, 67, glGraphics.getWidth() / (float) glGraphics.getHeight(), 0.1F, 10.0F);
  96.            
  97.             gl.glMatrixMode(GL10.GL_MODELVIEW);
  98.             gl.glLoadIdentity();
  99.            
  100.             //gl.glTranslatef(0, -1, 0);
  101.             //gl.glRotatef(20, 1, 0, 0);
  102.            
  103.             gl.glEnable(GL10.GL_DEPTH_TEST);
  104.             gl.glEnable(GL10.GL_TEXTURE_2D);
  105.            
  106.             texture.bind();
  107.            
  108.             cube.bind();
  109.             gl.glTranslatef(0, 0, -3);
  110.             gl.glRotatef(angle, 0, 1, 0);
  111.             cube.draw(GL10.GL_TRIANGLES, 0, 36);
  112.             cube.unbind();
  113.            
  114.             gl.glDisable(GL10.GL_TEXTURE_2D);
  115.             gl.glDisable(GL10.GL_DEPTH_TEST);
  116.         }
  117.  
  118.         @Override
  119.         public void pause() {}
  120.  
  121.         @Override
  122.         public void resume() {
  123.             texture.reload();
  124.         }
  125.  
  126.         @Override
  127.         public void dispose() {}
  128.        
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement