Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // glDrawArrays ひとまとめで描画Ver.
- private boolean chrInit = false;
- private int[] chrVertex_;
- private int[] chrTexture_;
- private int chrVertexPos_;
- private int chrTexturePos_;
- private void putVertex(int x,int y) { chrVertex_[chrVertexPos_++]=x; chrVertex_[chrVertexPos_++]=y; chrVertex_[chrVertexPos_++]=0;}
- private void putTexture(int x,int y) { chrTexture_[chrTexturePos_++]=x; chrTexture_[chrTexturePos_++]=y; }
- private ByteBuffer bb1;
- private ByteBuffer bb2;
- private IntBuffer chrVertexBuffer;
- private IntBuffer chrTextureBuffer;
- public void onDrawFrame(GL10 gl)
- {
- frame++;
- updateFPS();
- testSprite.update();
- if ( !chrInit ) {
- // 描画関連初期化
- // 頂点バッファ
- int n = testSprite.sprites.length;
- chrVertex_ = new int[n * 18];
- chrTexture_ = new int[n * 12];
- // ダイレクトバッファ確保
- ByteBuffer bb1=ByteBuffer.allocateDirect(n *18*4);
- bb1.order(ByteOrder.nativeOrder());
- chrVertexBuffer = bb1.asIntBuffer();
- bb2=ByteBuffer.allocateDirect(n *12*4);
- bb2.order(ByteOrder.nativeOrder());
- chrTextureBuffer = bb2.asIntBuffer();
- chrInit = true;
- }
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- float rotation = (float) (frame % 60) * 6.0f;
- gl.glEnable(GL10.GL_BLEND);
- gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
- gl.glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glBindTexture(GL10.GL_TEXTURE_2D, iconTextureNo);
- chrVertexPos_ = 0;
- chrTexturePos_ = 0;
- int x,y,size=16<<16,full=1<<16;
- int xsize=size,ysize=size;
- int x0,y0,x1,y1,x2,y2,x3,y3;
- int cosed,sined;
- for (Sprite sprite : testSprite.sprites) {
- x = sprite.x << 16;
- y = sprite.y << 16;
- cosed = (int)(size * Math.cos(rotation));
- sined = (int)(size * Math.sin(rotation));
- x0 = x+(int)(-cosed - -sined);
- y0 = y+(int)(-sined + -cosed);
- x1 = x+(int)(-cosed - sined);
- y1 = y+(int)(-sined + cosed);
- x2 = x+(int)( cosed - -sined);
- y2 = y+(int)( sined + -cosed);
- x3 = x+(int)( cosed - sined);
- y3 = y+(int)( sined + cosed);
- putVertex(x0,y0);
- putVertex(x1,y1);
- putVertex(x2,y2);
- putVertex(x2,y2);
- putVertex(x1,y1);
- putVertex(x3,y3);
- putTexture(0 ,0);
- putTexture(0 ,full);
- putTexture(full ,0);
- putTexture(full ,0);
- putTexture(0 ,full);
- putTexture(full ,full);
- }
- chrVertexBuffer.position(0);
- chrVertexBuffer.put(chrVertex_);
- chrVertexBuffer.position(0);
- chrTextureBuffer.position(0);
- chrTextureBuffer.put(chrTexture_);
- chrTextureBuffer.position(0);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity();
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- gl.glVertexPointer(3, GL10.GL_FIXED, 0, chrVertexBuffer);
- gl.glTexCoordPointer(2, GL10.GL_FIXED, 0, chrTextureBuffer);
- gl.glDrawArrays(GL10.GL_TRIANGLES, 0, chrVertex_.length / 3);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- gl.glFlush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement