title: opengles put bitmap outside the sphere
body: <p>i want to put the texture out the sphere,i search some link </p>
  
  <p><a href="https://github.com/kibotu/net.gtamps/blob/refactoring3d/android/graphic/src/net/gtamps/android/renderer/graph/scene/primitives/Sphere.java" rel="nofollow">https://github.com/kibotu/net.gtamps/blob/refactoring3d/android/graphic/src/net/gtamps/android/renderer/graph/scene/primitives/Sphere.java</a></p>
  
  <p><a href="https://github.com/ejeinc/RajawaliCardboardExample" rel="nofollow">https://github.com/ejeinc/RajawaliCardboardExample</a></p>
  
  <p>all are put the texture inside of the sphere. how to do this </p>
  
  <p>i do a texture inside of the sphere </p>
  
  <pre><code>public class SphereModel {
  // Init variable value
  private final int INVALID_STATE = -1;
  int mProgram = INVALID_STATE;
  int muMVPMatrixHandle = -1;
  int muMMatrixHandle = -1;// 
  int maCameraHandle = -1; // 
  int maPositionHandle = -1; // 
  int maNormalHandle = -1; //
  int maTexCoorHandle = -1; // 
  int maSunLightLocationHandle = -1;
  int uDayTexHandle = -1;
  String mVertexShader;
  String mFragmentShader;
  FloatBuffer mVertexBuffer;
  FloatBuffer mTexCoorBuffer;
  int vCount = 0;
  
  float[] mvpM = new float[16];
  float[] mM = new float[16];
  
  
  
  
  public SphereModel(Resources r, float radius) {
  
      initVertexData(radius);
  
      initShader(r);
  
      Matrix.setIdentityM(mvpM, 0);
      Matrix.setIdentityM(mM, 0);
  
      Matrix.translateM(mM, 0, 0, 0, 0);
  }
  
  
  public void initVertexData(float r) {
      // ================begin============================
      final float UNIT_SIZE = 0.5f;
      ArrayList&lt;Float&gt; alVertix = new ArrayList&lt;Float&gt;();
      final float angleSpan = 10f;
      for (float vAngle = 90; vAngle &gt; -90; vAngle = vAngle - angleSpan) {
          for (float hAngle = 360; hAngle &gt; 0; hAngle = hAngle - angleSpan) {
  
              double xozLength = r * UNIT_SIZE
                      * Math.cos(Math.toRadians(vAngle));
              float x1 = (float) (xozLength * Math
                      .cos(Math.toRadians(hAngle)));
              float z1 = (float) (xozLength * Math
                      .sin(Math.toRadians(hAngle)));
              float y1 = (float) (r * UNIT_SIZE * Math.sin(Math
                      .toRadians(vAngle)));
  
              xozLength = r * UNIT_SIZE
                      * Math.cos(Math.toRadians(vAngle - angleSpan));
              float x2 = (float) (xozLength * Math
                      .cos(Math.toRadians(hAngle)));
              float z2 = (float) (xozLength * Math
                      .sin(Math.toRadians(hAngle)));
              float y2 = (float) (r * UNIT_SIZE * Math.sin(Math
                      .toRadians(vAngle - angleSpan)));
  
              xozLength = r * UNIT_SIZE
                      * Math.cos(Math.toRadians(vAngle - angleSpan));
              float x3 = (float) (xozLength * Math.cos(Math.toRadians(hAngle
                      - angleSpan)));
              float z3 = (float) (xozLength * Math.sin(Math.toRadians(hAngle
                      - angleSpan)));
              float y3 = (float) (r * UNIT_SIZE * Math.sin(Math
                      .toRadians(vAngle - angleSpan)));
  
              xozLength = r * UNIT_SIZE * Math.cos(Math.toRadians(vAngle));
              float x4 = (float) (xozLength * Math.cos(Math.toRadians(hAngle
                      - angleSpan)));
              float z4 = (float) (xozLength * Math.sin(Math.toRadians(hAngle
                      - angleSpan)));
              float y4 = (float) (r * UNIT_SIZE * Math.sin(Math
                      .toRadians(vAngle)));
  
              alVertix.add(x1);
              alVertix.add(y1);
              alVertix.add(z1);
              alVertix.add(x2);
              alVertix.add(y2);
              alVertix.add(z2);
              alVertix.add(x4);
              alVertix.add(y4);
              alVertix.add(z4);
  
              alVertix.add(x4);
              alVertix.add(y4);
              alVertix.add(z4);
              alVertix.add(x2);
              alVertix.add(y2);
              alVertix.add(z2);
              alVertix.add(x3);
              alVertix.add(y3);
              alVertix.add(z3);
          }
      }
      vCount = alVertix.size() / 3;
  
      float vertices[] = new float[vCount * 3];
      for (int i = 0; i &lt; alVertix.size(); i++) {
          vertices[i] = alVertix.get(i);
      }
  
      ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
      vbb.order(ByteOrder.nativeOrder());
      mVertexBuffer = vbb.asFloatBuffer();
      mVertexBuffer.put(vertices);
      mVertexBuffer.position(0);
  
      float[] texCoor = generateTexCoor(
              (int) (360 / angleSpan), 
              (int) (180 / angleSpan) 
      );
      ByteBuffer llbb = ByteBuffer.allocateDirect(texCoor.length * 4);
      llbb.order(ByteOrder.nativeOrder());
      mTexCoorBuffer = llbb.asFloatBuffer();
      mTexCoorBuffer.put(texCoor);
      mTexCoorBuffer.position(0);
  }
  
  public void initShader(Resources r) { 
  
      mVertexShader = ShaderUtil.loadFromAssetsFile("vertex_tex_f.sh", r);
      ShaderUtil.checkGlError("==ss==");
  
      mFragmentShader = ShaderUtil.loadFromAssetsFile("frag_tex_f.sh", r);
  
      ShaderUtil.checkGlError("==ss==");
      mProgram = ShaderUtil.createProgram(mVertexShader, mFragmentShader);
  
      maPositionHandle = GLES20.glGetAttribLocation(mProgram, "aPosition");
  
      maTexCoorHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoor");
  
      muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix");
  }
  
  public void drawSelf(Eye transform, int textureId) {
  
      GLES20.glUseProgram(mProgram);
  
  
      GLES20.glEnable(GLES20.GL_CULL_FACE);
      GLES20.glFrontFace(GLES20.GL_CW);
  
  
  
  
      if(ThunderConstant.MODE_CHOICE==1){
  
          if(ThunderConstant.TYPE_CHOICE==0){
              Matrix.setLookAtM(mM, 0, 0, 0, 0, 0f, 0f, -10f, 0f, 1f, 0f);
          }else if(ThunderConstant.TYPE_CHOICE==1){
              Matrix.setLookAtM(mM, 0, 0, 0, 0, 0f, 0f, -10f, 0f, 1f, 0f);
              Matrix.translateM(mM, 0, 0, -1.5f, 0);
          }else if(ThunderConstant.TYPE_CHOICE==2){
  
          }
      }else{
  
          if(ThunderConstant.TYPE_CHOICE==0){
              Matrix.setLookAtM(mM, 0, 0, 0, 0, 0f, 0f, -10f, 0f, 1f, 0f);
          }else if(ThunderConstant.TYPE_CHOICE==1){
              Matrix.setLookAtM(mM, 0, 0, 0, 0, 0f, 0f, -10f, 0f, 1f, 0f);
              Matrix.translateM(mM, 0, 0, -1.5f, 0);
          }else if(ThunderConstant.TYPE_CHOICE==2){
  
          }
  
      }
  
  
  
      Matrix.multiplyMM(mvpM, 0, transform.getEyeView(), 0, mM, 0);
      Matrix.multiplyMM(mvpM, 0, transform.getPerspective(0.1f, 200f), 0, mvpM, 0);
  
      if(PanoramaImageActivityNormalMode.isGestureControl){
          GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false,
                  MatrixState.getFinalMatrixOfFullImage(transform), 0);
      }else{
          GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mvpM, 0);
      }
  
  
      GLES20.glVertexAttribPointer(
  
              maPositionHandle, 3, GLES20.GL_FLOAT, false, 3 * 4,
              mVertexBuffer);
      GLES20.glVertexAttribPointer(
  
              maTexCoorHandle, 2, GLES20.GL_FLOAT, false, 2 * 4,
              mTexCoorBuffer);
  
      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
  
  
      GLES20.glEnableVertexAttribArray(maPositionHandle);
      GLES20.glEnableVertexAttribArray(maTexCoorHandle);
      // GLES20.glEnableVertexAttribArray(maNormalHandle);
  
      GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vCount);
  }
  
  
  
  
  
  public float[] generateTexCoor(int bw, int bh) {
      float[] result = new float[bw * bh * 6 * 2];
      // float sizew=1.0f/bw;
      // float sizeh=1.0f/bh;
      float sizew = 1.0f / bw;
      float sizeh = 1.0f / bh;
      int c = 0;
      for (int i = 0; i &lt; bh; i++) {
          for (int j = 0; j &lt; bw; j++) {
  
              float s = 1 - j * sizew;
              float t = i * sizeh;
  
              result[c++] = s;
              result[c++] = t;
  
              result[c++] = s;
              result[c++] = t + sizeh;
  
              result[c++] = s - sizew;
              result[c++] = t;
  
              //
              result[c++] = s - sizew;
              result[c++] = t;
  
              result[c++] = s;
              result[c++] = t + sizeh;
  
              result[c++] = s - sizew;
              result[c++] = t + sizeh;
          }
      }
      return result;
  
  }
  
  /**
   * recycle resource
   */
  public void recyleRecource() {
      if (mProgram != INVALID_STATE) {
          GLES20.glDeleteProgram(mProgram);
          mProgram = INVALID_STATE;
      }
  }
  </code></pre>
  
  <p>} </p>
  
  <p>how to modify it make the texture inside of the sphere</p>