Beispiel #1
0
  @Override
  public void initialize(Context context, ProgramManager programManager) {
    lineShaderProgram = programManager.getProgram(ProgramManager.PROGRAM.LINE);

    textureDataHandler = TextureLoader.loadTexture(context, R.drawable.game209, GLES20.GL_LINEAR);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);

    int socketTextureDataHandler =
        TextureLoader.loadTexture(context, R.drawable.node_socket, GLES20.GL_LINEAR);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);

    mCorrectNodeTextureHandle =
        TextureLoader.loadTexture(context, R.drawable.game209, GLES20.GL_LINEAR);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);

    mWrongNodeTextureHandle =
        TextureLoader.loadTexture(context, R.drawable.game210, GLES20.GL_LINEAR);
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);

    mNodeBatch = new SpriteBatch(SpriteBatch.COLORED_VERTEX_3D, textureDataHandler);
    mNodeBatch.setFiltered(true);
    mNodeBatch.initialize(context, programManager);

    mSocketBatch = new SpriteBatch(SpriteBatch.VERTEX_3D, socketTextureDataHandler);
    mSocketBatch.setFiltered(true);
    mSocketBatch.useDepthTest(false);
    mSocketBatch.initialize(context, programManager);

    mConnectionsBatch = new Line3DBatch();
    mConnectionsBatch.initialize(context, programManager);

    mDottedBatch = new DottedLine3DBatch(0.7f, 0.8f);
    mDottedBatch.initialize(context, programManager);

    mSprite = new Sprite(Vector3f.getZero(), 2.0f, 2.0f);
    mSprite.setFiltered(true);
    mSprite.setTexture(textureDataHandler);
    mSprite.initialize(context, programManager);

    for (int i = 0; i < nodes.length; i++) {
      nodes[i].getSprite().setFiltered(true).initialize(context, programManager);
    }

    super.initialize(context, programManager);
  }
Beispiel #2
0
  public Texture(Context context, int idpicture) {

    int[] names = new int[1];
    GLES20.glGenTextures(1, names, 0);
    name = names[0];
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, name);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), idpicture);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
  }
 private void load(Bitmap bitmap, boolean mipmap) {
   int[] textureIds = new int[1];
   GLES20.glGenTextures(1, textureIds, 0);
   textureId = textureIds[0];
   this.width = bitmap.getWidth();
   this.height = bitmap.getHeight();
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
   GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
   if (mipmap) {
     GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
     setFilter(GLES20.GL_LINEAR_MIPMAP_NEAREST, GLES20.GL_LINEAR_MIPMAP_LINEAR);
   } else setFilter(GLES20.GL_NEAREST, GLES20.GL_LINEAR);
   bitmap.recycle();
   GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
 }
  // 初始化纹理
  public int initTexture(int drawableId) {
    // 生成纹理ID
    int[] textures = new int[1];
    GLES20.glGenTextures(
        1, // 产生的纹理id的数量
        textures, // 纹理id的数组
        0 // 偏移量
        );
    int textureId = textures[0];
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureId);
    // 非Mipmap纹理采样过滤参数
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    // ST方向纹理拉伸方式
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);

    // 通过输入流加载图片===============begin===================
    InputStream is = this.getResources().openRawResource(drawableId);
    Bitmap bitmapTmp;
    try {
      bitmapTmp = BitmapFactory.decodeStream(is);
    } finally {
      try {
        is.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    // 实际加载纹理,换成这个方法后,如果图片格式有问题,会抛出图片格式异常,不再会误显示其他异常
    GLUtils.texImage2D(
        GLES20.GL_TEXTURE_2D, // 纹理类型
        0,
        GLUtils.getInternalFormat(bitmapTmp),
        bitmapTmp, // 纹理图像
        GLUtils.getType(bitmapTmp),
        0 // 纹理边框尺寸
        );
    // 自动生成Mipmap纹理
    GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    // 释放纹理图
    bitmapTmp.recycle();
    // 返回纹理ID
    return textureId;
  }
Beispiel #5
0
 @Override
 public void glGenerateMipmap(int target) {
   GLES20.glGenerateMipmap(target);
 }
Beispiel #6
0
 @Override
 public void generateMipmap(final int target) {
   checkOpenGLThread();
   GLES20.glGenerateMipmap(target);
 }