Android Open Source - block-composer Select Box Renderer






From Project

Back to project page block-composer.

License

The source code is released under:

MIT License

If you think the Android project block-composer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package bwr.blockcomposer.models;
//  w  w  w.j  a  va  2 s .c  om
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.CharBuffer;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

public class SelectBoxRenderer {
  private final static int FLOAT_SIZE = 4;
  private final static int CHAR_SIZE = 2;
    
  private int numVertices;
  
  private IntBuffer vertexBuffer;
  private CharBuffer indexBuffer;
  
  public void render(GL10 gl) {
    gl.glDisable(GL10.GL_LIGHTING);
    gl.glDisable(GL10.GL_TEXTURE_2D);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FIXED, 0, vertexBuffer);
    
    gl.glLineWidthx(1<<16);
    gl.glColor4f(0.99609f,0.25390f,0.88281f, 1.0f);

    gl.glDrawElements(GL10.GL_LINES, numVertices, GL10.GL_UNSIGNED_SHORT, indexBuffer);
    
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnable(GL10.GL_LIGHTING);
    gl.glEnable(GL10.GL_TEXTURE_2D);
  }
  
  private void putVertex(int x, int y, int z) {
    vertexBuffer.put(x);
    vertexBuffer.put(y);
    vertexBuffer.put(z);
  }
  
  public SelectBoxRenderer() {
    
    numVertices = 24;
            
    vertexBuffer = ByteBuffer.allocateDirect(numVertices*3*FLOAT_SIZE).order(ByteOrder.nativeOrder()).asIntBuffer();
    indexBuffer = ByteBuffer.allocateDirect(numVertices*CHAR_SIZE).order(ByteOrder.nativeOrder()).asCharBuffer();
    
        char index = 0; // vertex index
        
        putVertex(0,0,0);  indexBuffer.put(index++);
      putVertex(1<<16,0,0); indexBuffer.put(index++);

      putVertex(0,0,1<<16); indexBuffer.put(index++);
      putVertex(1<<16,0,1<<16); indexBuffer.put(index++);

      putVertex(0,1<<16,0); indexBuffer.put(index++);
      putVertex(1<<16,1<<16,0); indexBuffer.put(index++);

      putVertex(0,1<<16,1<<16); indexBuffer.put(index++);
      putVertex(1<<16,1<<16,1<<16); indexBuffer.put(index++);

      putVertex(0,0,0); indexBuffer.put(index++);
      putVertex(0,0,1<<16); indexBuffer.put(index++);

      putVertex(0,1<<16,0); indexBuffer.put(index++);
      putVertex(0,1<<16,1<<16); indexBuffer.put(index++);

      putVertex(1<<16,0,0); indexBuffer.put(index++);
      putVertex(1<<16,0,1<<16); indexBuffer.put(index++);

      putVertex(1<<16,1<<16,0); indexBuffer.put(index++);
      putVertex(1<<16,1<<16,1<<16); indexBuffer.put(index++);

      putVertex(0,0,0); indexBuffer.put(index++);
      putVertex(0,1<<16,0); indexBuffer.put(index++);

      putVertex(1<<16,0,0); indexBuffer.put(index++);
      putVertex(1<<16,1<<16,0); indexBuffer.put(index++);

      putVertex(0,0,1<<16); indexBuffer.put(index++);
      putVertex(0,1<<16,1<<16); indexBuffer.put(index++);

      putVertex(1<<16,0,1<<16); indexBuffer.put(index++);
      putVertex(1<<16,1<<16,1<<16); indexBuffer.put(index++);
      
    
    vertexBuffer.position(0);
    indexBuffer.position(0);
  }
}




Java Source Code List

bwr.blockcomposer.AnimationFinishedListener.java
bwr.blockcomposer.BlockComposerActivity.java
bwr.blockcomposer.BlockComposerRenderer.java
bwr.blockcomposer.BlockComposer.java
bwr.blockcomposer.Camera.java
bwr.blockcomposer.GameResources.java
bwr.blockcomposer.OnUpdateAction.java
bwr.blockcomposer.gamedata.Block.java
bwr.blockcomposer.gamedata.GameEntity.java
bwr.blockcomposer.gamedata.GameState.java
bwr.blockcomposer.gamedata.LevelDimensions.java
bwr.blockcomposer.gamedata.LevelMask.java
bwr.blockcomposer.gamedata.LevelMetadata.java
bwr.blockcomposer.gamedata.LevelStore.java
bwr.blockcomposer.gamedata.Level.java
bwr.blockcomposer.gamedata.Move.java
bwr.blockcomposer.gamedata.StaticLevelStore.java
bwr.blockcomposer.gamedata.UserLevelStore.java
bwr.blockcomposer.misc.GLUtility.java
bwr.blockcomposer.misc.Timer.java
bwr.blockcomposer.models.AxisRenderer.java
bwr.blockcomposer.models.Model.java
bwr.blockcomposer.models.SelectBoxRenderer.java
bwr.blockcomposer.modes.EditMode.java
bwr.blockcomposer.modes.GameDialogMode.java
bwr.blockcomposer.modes.GameMode.java
bwr.blockcomposer.modes.LevelImportMode.java
bwr.blockcomposer.modes.LevelSelectMode.java
bwr.blockcomposer.modes.LogoDisplayMode.java
bwr.blockcomposer.modes.ModeController.java
bwr.blockcomposer.modes.Mode.java
bwr.blockcomposer.modes.OverlayMode.java
bwr.blockcomposer.types.FlipRotateFloat.java
bwr.blockcomposer.types.FloatValueVector3.java
bwr.blockcomposer.types.FloatValue.java
bwr.blockcomposer.types.IntVector.java
bwr.blockcomposer.types.RotatingFloat.java
bwr.blockcomposer.ui.TextRenderer.java
bwr.blockcomposer.ui.UIElementPicture.java
bwr.blockcomposer.ui.UIElementText.java
bwr.blockcomposer.ui.UIElement.java