Advertisement
fslasht

Untitled

May 12th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.23 KB | None | 0 0
  1.     // glDrawArrays ひとまとめで描画Ver.
  2.  
  3.     private boolean chrInit = false;
  4.     private int[] chrVertex_;
  5.     private int[] chrTexture_;
  6.     private int chrVertexPos_;
  7.     private int chrTexturePos_;
  8.     private void putVertex(int x,int y) { chrVertex_[chrVertexPos_++]=x; chrVertex_[chrVertexPos_++]=y; chrVertex_[chrVertexPos_++]=0;}
  9.     private void putTexture(int x,int y) { chrTexture_[chrTexturePos_++]=x; chrTexture_[chrTexturePos_++]=y; }
  10.     private ByteBuffer bb1;
  11.     private ByteBuffer bb2;
  12.     private IntBuffer chrVertexBuffer;
  13.     private IntBuffer chrTextureBuffer;
  14.  
  15.     public void onDrawFrame(GL10 gl)
  16.     {
  17.         frame++;
  18.         updateFPS();
  19.         testSprite.update();
  20.  
  21.         if ( !chrInit ) {
  22.             // 描画関連初期化
  23.             // 頂点バッファ
  24.             int n = testSprite.sprites.length;
  25.             chrVertex_ = new int[n * 18];
  26.             chrTexture_ = new int[n * 12];
  27.  
  28.             // ダイレクトバッファ確保
  29.             ByteBuffer bb1=ByteBuffer.allocateDirect(n *18*4);
  30.             bb1.order(ByteOrder.nativeOrder());
  31.             chrVertexBuffer = bb1.asIntBuffer();
  32.  
  33.             bb2=ByteBuffer.allocateDirect(n *12*4);
  34.             bb2.order(ByteOrder.nativeOrder());
  35.             chrTextureBuffer = bb2.asIntBuffer();
  36.  
  37.             chrInit = true;
  38.         }
  39.  
  40.  
  41.         gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  42.  
  43.         gl.glMatrixMode(GL10.GL_MODELVIEW);
  44.  
  45.         float rotation = (float) (frame % 60) * 6.0f;
  46.         gl.glEnable(GL10.GL_BLEND);
  47.         gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
  48.         gl.glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
  49.  
  50.         gl.glEnable(GL10.GL_TEXTURE_2D);
  51.         gl.glBindTexture(GL10.GL_TEXTURE_2D, iconTextureNo);
  52.  
  53.         chrVertexPos_ = 0;
  54.         chrTexturePos_ = 0;
  55.         int x,y,size=16<<16,full=1<<16;
  56.  
  57.         int xsize=size,ysize=size;
  58.         int x0,y0,x1,y1,x2,y2,x3,y3;
  59.         int cosed,sined;
  60.         for (Sprite sprite : testSprite.sprites) {
  61.             x = sprite.x << 16;
  62.             y = sprite.y << 16;
  63.  
  64.             cosed = (int)(size * Math.cos(rotation));
  65.             sined = (int)(size * Math.sin(rotation));
  66.  
  67.             x0 = x+(int)(-cosed - -sined);
  68.             y0 = y+(int)(-sined + -cosed);
  69.             x1 = x+(int)(-cosed -  sined);
  70.             y1 = y+(int)(-sined +  cosed);
  71.             x2 = x+(int)( cosed - -sined);
  72.             y2 = y+(int)( sined + -cosed);
  73.             x3 = x+(int)( cosed -  sined);
  74.             y3 = y+(int)( sined +  cosed);
  75.  
  76.  
  77.             putVertex(x0,y0);
  78.             putVertex(x1,y1);
  79.             putVertex(x2,y2);
  80.  
  81.             putVertex(x2,y2);
  82.             putVertex(x1,y1);
  83.             putVertex(x3,y3);
  84.  
  85.             putTexture(0        ,0);
  86.             putTexture(0        ,full);
  87.             putTexture(full     ,0);
  88.  
  89.             putTexture(full     ,0);
  90.             putTexture(0        ,full);
  91.             putTexture(full     ,full);
  92.  
  93.         }
  94.  
  95.         chrVertexBuffer.position(0);
  96.         chrVertexBuffer.put(chrVertex_);
  97.         chrVertexBuffer.position(0);
  98.  
  99.         chrTextureBuffer.position(0);
  100.         chrTextureBuffer.put(chrTexture_);
  101.         chrTextureBuffer.position(0);
  102.  
  103.         gl.glMatrixMode(GL10.GL_MODELVIEW);
  104.  
  105.         gl.glLoadIdentity();
  106.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  107.         gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  108.  
  109.         gl.glVertexPointer(3, GL10.GL_FIXED, 0, chrVertexBuffer);
  110.         gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, chrTextureBuffer);
  111.  
  112.  
  113.         gl.glDrawArrays(GL10.GL_TRIANGLES, 0, chrVertex_.length / 3);
  114.  
  115.         gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  116.         gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
  117.  
  118.         gl.glFlush();
  119.  
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement