Ejemplo n.º 1
0
  protected SurfaceTexture createSurfaceTexture() {
    int tex[] = new int[1];
    GLES20.glGenTextures(1, tex, 0);
    //		GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex[0]);
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(
        GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    textureName = tex[0];
    Log.d("OESTexture", "createSurfaceTexture textureName:" + textureName);
    final SurfaceTexture t = new SurfaceTexture(tex[0]);
    t.setOnFrameAvailableListener(
        new SurfaceTexture.OnFrameAvailableListener() {

          @Override
          public void onFrameAvailable(SurfaceTexture surfaceTexture) {
            textureUpdated = true;
            // Log.d("OESTexture", "onFrameAvailable textureName:" + textureName);
          }
        });
    return t;
  }
Ejemplo n.º 2
0
  boolean InitTexture(int ResourceId) {
    /*
     * Android
     * public static void glGenTextures (int n, int[] textures, int offset)
     * Returns n currently unused names for texture objects in the array textures.
     */
    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);

    /*
     * Android
     * public static void glBindTexture (int target, int texture)
     */
    m_TextureId = textures[0];
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, m_TextureId);

    // Loads in Texture from Resource File
    LoadTexture(ResourceId);

    /*
     * Android
     * static void	 texImage2D(int target, int level, Bitmap bitmap, int border)
     * A version of texImage2D that determines the internalFormat and type automatically.
     */
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, m_Bitmap, 0);

    return true;
  }
Ejemplo n.º 3
0
  static void init(int num) {
    pool = null;

    TextureObject to;

    int[] textureIds = new int[num];
    GLES20.glGenTextures(num, textureIds, 0);

    for (int i = 1; i < num; i++) {
      initTexture(textureIds[i]);
      to = new TextureObject(textureIds[i]);

      to.next = pool;
      pool = to;
    }

    mBitmaps = new ArrayList<Bitmap>(10);

    for (int i = 0; i < 4; i++) {
      Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);

      mBitmaps.add(bitmap);
    }

    mBitmapFormat = GLUtils.getInternalFormat(mBitmaps.get(0));
    mBitmapType = GLUtils.getType(mBitmaps.get(0));
  }
Ejemplo n.º 4
0
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false;

      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
 /** Inform this View of the dimensions of frames coming from |stream|. */
 public void setSize(Endpoint stream, int width, int height) {
   // Generate 3 texture ids for Y/U/V and place them into |textures|,
   // allocating enough storage for |width|x|height| pixels.
   int[] textures = yuvTextures[stream == Endpoint.LOCAL ? 0 : 1];
   GLES20.glGenTextures(3, textures, 0);
   for (int i = 0; i < 3; ++i) {
     int w = i == 0 ? width : width / 2;
     int h = i == 0 ? height : height / 2;
     GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i);
     GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[i]);
     GLES20.glTexImage2D(
         GLES20.GL_TEXTURE_2D,
         0,
         GLES20.GL_LUMINANCE,
         w,
         h,
         0,
         GLES20.GL_LUMINANCE,
         GLES20.GL_UNSIGNED_BYTE,
         null);
     GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
     GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
     GLES20.glTexParameterf(
         GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
     GLES20.glTexParameterf(
         GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
   }
   checkNoGLES2Error();
 }
Ejemplo n.º 6
0
  public static int loadTexture(final Context context, final int resourceId) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      final Bitmap bitmap =
          BitmapFactory.decodeResource(context.getResources(), resourceId, options);

      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Ejemplo n.º 7
0
  public static int loadTexture2(final Bitmap bitmap) {
    final int[] textureHandle = new int[1];

    glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      // Bind to the texture in OpenGL
      glBindTexture(GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

      // Load the bitmap into the bound texture.
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);

      //			Buffer byteBuffer = ByteBuffer.allocate(bitmap.getByteCount());
      //			bitmap.copyPixelsToBuffer(byteBuffer);
      //			glTexImage2D(GL_TEXTURE_2D, 0, GLES20.GL_RGB, bitmap.getWidth(), bitmap.getHeight(),
      //					0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, byteBuffer);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    } else {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Ejemplo n.º 8
0
  /**
   * Creates a texture from raw data.
   *
   * @param data Image data, in a "direct" ByteBuffer.
   * @param width Texture width, in pixels (not bytes).
   * @param height Texture height, in pixels.
   * @param format Image data format (use constant appropriate for glTexImage2D(), e.g. GL_RGBA).
   * @return Handle to texture.
   */
  public static int createImageTexture(ByteBuffer data, int width, int height, int format) {
    int[] textureHandles = new int[1];
    int textureHandle;

    GLES20.glGenTextures(1, textureHandles, 0);
    textureHandle = textureHandles[0];
    GlUtil.checkGlError("glGenTextures");

    // Bind the texture handle to the 2D texture target.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle);

    // Configure min/mag filtering, i.e. what scaling method do we use if what we're rendering
    // is smaller or larger than the source image.
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GlUtil.checkGlError("loadImageTexture");

    // Load the data from the buffer into the texture handle.
    GLES20.glTexImage2D(
        GLES20.GL_TEXTURE_2D, /*level*/
        0,
        format,
        width,
        height, /*border*/
        0,
        format,
        GLES20.GL_UNSIGNED_BYTE,
        data);
    GlUtil.checkGlError("loadImageTexture");

    return textureHandle;
  }
Ejemplo n.º 9
0
 private void makeTexture() {
   int[] handleArr = new int[1];
   glGenTextures(1, handleArr, 0);
   handle = handleArr[0];
   glBindTexture(GL_TEXTURE_2D, handle);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 }
Ejemplo n.º 10
0
  private void loadTexture(Bitmap b) {
    GLES20.glGenTextures(1, textures, 0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);

    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);

    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, b, 0);

    b.recycle();
  }
Ejemplo n.º 11
0
 public static void a(int i, int j, IntBuffer intbuffer) {
   intbuffer.position(0);
   GLES20.glGenTextures(1, intbuffer);
   GLES20.glBindTexture(3553, intbuffer.get(0));
   GLES20.glTexParameteri(3553, 10241, 9729);
   GLES20.glTexParameteri(3553, 10240, 9729);
   GLES20.glTexParameteri(3553, 10242, 33071);
   GLES20.glTexParameteri(3553, 10243, 33071);
   GLES20.glTexImage2D(3553, 0, 6408, i, j, 0, 6408, 5121, null);
   GLES20.glFramebufferTexture2D(36160, 36064, 3553, intbuffer.get(0), 0);
 }
Ejemplo n.º 12
0
  private static int createTexture() {
    int[] texture = new int[1];

    GLES20.glGenTextures(1, texture, 0);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture[0]);
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameterf(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);

    return texture[0];
  }
Ejemplo n.º 13
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);
  }
Ejemplo n.º 14
0
  /** The Surface is created/init() */
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    Log.i("Almalence", "GLLayer.onSurfaceCreated()");

    PluginManager.getInstance().onGLSurfaceCreated(gl, config);

    if (PluginManager.getInstance().shouldPreviewToGPU()) {
      final int[] tex = new int[1];
      GLES20.glGenTextures(1, tex, 0);
      this.texture_preview = tex[0];

      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, this.texture_preview);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameteri(
          GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);

      this.surfaceTexture = new SurfaceTexture(this.texture_preview);
      this.surfaceTexture.setOnFrameAvailableListener(
          new OnFrameAvailableListener() {
            @Override
            public void onFrameAvailable(final SurfaceTexture surfaceTexture) {
              PluginManager.getInstance().onFrameAvailable();
            }
          });

      final Camera camera = CameraController.getCamera();
      if (camera == null) {
        return;
      }

      try {
        camera.setDisplayOrientation(90);
      } catch (RuntimeException e) {
        e.printStackTrace();
      }

      try {
        camera.setPreviewTexture(this.surfaceTexture);
      } catch (final IOException e) {
        e.printStackTrace();
      }

      camera.startPreview();
    }
  }
  private void loadTextures() {
    // Generate textures
    GLES20.glGenTextures(2, mTextures, 0);
    mImageWidth = bitmapForScreen.getWidth();
    mImageHeight = bitmapForScreen.getHeight();
    mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);

    // Upload to texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapForScreen, 0);

    // Set texture parameters
    GLToolbox.initTexParams();
  }
Ejemplo n.º 16
0
  public Texture loadSingleTexture(int resId, int slotId, int compression) {

    int[] texturesId = new int[1];

    GLES20.glGenTextures(texturesId.length, texturesId, 0);

    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

    Texture mTexture = new Texture(compression, texturesId[0], slotId, resId);
    mTexture.load(context);
    textures.add(mTexture);

    return mTexture;
  }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
  private int loadTexture(String path) {
    String fullPath = "gfx";
    fullPath += path;
    Bitmap bitmap = null;
    try { // Get reference to AssetManager

      AssetManager mngr = _context.getAssets();
      // Create an input stream to read from the asset folder
      InputStream ins = mngr.open(fullPath);
      // Convert the input stream into a bitmap
      bitmap = BitmapFactory.decodeStream(ins);
    } catch (final IOException e) {
      e.printStackTrace();
      Toast.makeText(_context, "couldn't set image to background", Toast.LENGTH_LONG).show();
    }

    int h = firstBigger2power((float) bitmap.getHeight() / Utils.scaleFactrWidth);
    int w = firstBigger2power((float) bitmap.getWidth() / Utils.scaleFactrWidth);

    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inScaled = false; // No pre-scaling

      // Read in the resource
      // Bind to the texture in OpenGL
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      // Set filtering
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);

      // Load the bitmap into the bound texture.
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, Bitmap.createScaledBitmap(bitmap, w, h, true), 0);

      // Recycle the bitmap, since its data has been loaded into OpenGL.
      bitmap.recycle();
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Ejemplo n.º 19
0
  public static synchronized void uploadTexture(TextureObject to) {
    if (TextureRenderer.debug) Log.d("...", "upload texture " + to.id);

    if (to.id < 0) {
      int[] textureIds = new int[1];
      GLES20.glGenTextures(1, textureIds, 0);
      to.id = textureIds[0];
      initTexture(to.id);
      if (TextureRenderer.debug) Log.d("...", "new texture " + to.id);
    }

    uploadTexture(to, to.bitmap, mBitmapFormat, mBitmapType, TEXTURE_WIDTH, TEXTURE_HEIGHT);

    mBitmaps.add(to.bitmap);
    to.bitmap = null;
  }
Ejemplo n.º 20
0
  public Texture loadCubeMapTexture(
      int front, int left, int back, int right, int up, int down, int slotId, int compression) {

    int[] texturesId = new int[1];

    GLES20.glGenTextures(texturesId.length, texturesId, 0);

    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

    Texture mTexture =
        new Texture(compression, texturesId[0], slotId, front, left, back, right, up, down);
    mTexture.load(context);
    textures.add(mTexture);

    return mTexture;
  }
Ejemplo n.º 21
0
  public void confirmTextures() {

    if (textures != null && textures.size() > 0) {

      for (Texture each : textures) {
        if (!GLES20.glIsTexture(each.id)) {
          Log.d("MyLogs", "texture restored " + each.id);
          int[] texturesId = new int[] {each.id};
          GLES20.glDeleteTextures(1, texturesId, 0);
          GLES20.glGenTextures(1, texturesId, 0);

          each.reload(context, texturesId[0]);
        }
      }
    }
  }
Ejemplo n.º 22
0
 /**
  * create external texture
  *
  * @return texture ID
  */
 public static int initTex() {
   if (DEBUG) Log.v(TAG, "initTex:");
   final int[] tex = new int[1];
   GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
   GLES20.glGenTextures(1, tex, 0);
   GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, tex[0]);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
   GLES20.glTexParameteri(
       GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
   return tex[0];
 }
Ejemplo n.º 23
0
 @Override
 public ArrayList<IGLTextureId> genTextures(final int count) {
   checkOpenGLThread();
   final ArrayList<IGLTextureId> result = new ArrayList<IGLTextureId>(count);
   final int[] textureIds = new int[count];
   GLES20.glGenTextures(count, textureIds, 0);
   for (int i = 0; i < count; i++) {
     final int textureId = textureIds[i];
     if (textureId == 0) {
       ILogger.instance().logError("Can't create a textureId");
     } else {
       result.add(new GLTextureId_Android(textureId));
     }
   }
   return result;
 }
  /** Sets up texturing for the object */
  private void setupTextures(Object3D ob) {
    // create new texture ids if object has them
    if (ob.hasTexture()) {
      // number of textures
      int[] texIDs = ob.get_texID();
      int[] textures = new int[texIDs.length];
      _texIDs = new int[texIDs.length];
      // texture file ids
      int[] texFiles = ob.getTexFile();

      Log.d("TEXFILES LENGTH: ", texFiles.length + "");
      GLES20.glGenTextures(texIDs.length, textures, 0);

      for (int i = 0; i < texIDs.length; i++) {
        texIDs[i] = textures[i];

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texIDs[i]);

        // parameters
        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);

        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);

        InputStream is = mContext.getResources().openRawResource(texFiles[i]);
        Bitmap bitmap;
        try {
          bitmap = BitmapFactory.decodeStream(is);
        } finally {
          try {
            is.close();
          } catch (IOException e) {
            // Ignore.
          }
        }

        // create it
        GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
        bitmap.recycle();

        Log.d("ATTACHING TEXTURES: ", "Attached " + i);
      }
    }
  }
Ejemplo n.º 25
0
  public static int createTextureId(final int target) {
    final int[] textures = new int[1];

    // Generate one texture pointer...
    GLES20.glGenTextures(1, textures, 0);
    // ...and bind it to our array
    GLES20.glBindTexture(target, textures[0]);

    // Create Nearest Filtered Texture
    GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
    GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    // Different possible texture parameters, e.g. GLES20.GL_CLAMP_TO_EDGE
    GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    GLES20.glTexParameterf(target, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
    return textures[0];
  }
Ejemplo n.º 26
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;
  }
  // Function for initializing the renderer.
  private void initRendering() {
    mTeapot = new Teapot();
    mTextPlane = new TextPlane();

    mRenderer = Renderer.getInstance();

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, Vuforia.requiresAlpha() ? 0.0f : 1.0f);

    for (Texture t : mTextures) {
      GLES20.glGenTextures(1, t.mTextureID, 0);
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, t.mTextureID[0]);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexImage2D(
          GLES20.GL_TEXTURE_2D,
          0,
          GLES20.GL_RGBA,
          t.mWidth,
          t.mHeight,
          0,
          GLES20.GL_RGBA,
          GLES20.GL_UNSIGNED_BYTE,
          t.mData);
    }

    shaderProgramID =
        SampleUtils.createProgramFromShaderSrc(
            CubeShaders.CUBE_MESH_VERTEX_SHADER, CubeShaders.CUBE_MESH_FRAGMENT_SHADER);

    vertexHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexPosition");
    normalHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexNormal");
    textureCoordHandle = GLES20.glGetAttribLocation(shaderProgramID, "vertexTexCoord");
    mvpMatrixHandle = GLES20.glGetUniformLocation(shaderProgramID, "modelViewProjectionMatrix");
    texSampler2DHandle = GLES20.glGetUniformLocation(shaderProgramID, "texSampler2D");

    try {
      mBuildingsModel = new SampleApplication3DModel();
      mBuildingsModel.loadModel(mActivity.getResources().getAssets(), "ImageTargets/Buildings.txt");
    } catch (IOException e) {
      Log.e(LOGTAG, "Unable to load buildings");
    }

    // Hide the Loading Dialog
    mActivity.loadingDialogHandler.sendEmptyMessage(LoadingDialogHandler.HIDE_LOADING_DIALOG);
  }
Ejemplo n.º 28
0
  public static int loadTexture(Bitmap bitmap) {
    final int[] textureHandle = new int[1];

    GLES20.glGenTextures(1, textureHandle, 0);

    if (textureHandle[0] != 0) {
      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);

      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
      GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
      GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    }

    if (textureHandle[0] == 0) {
      throw new RuntimeException("Error loading texture.");
    }

    return textureHandle[0];
  }
Ejemplo n.º 29
0
  public static int LoadTexture(GLSurfaceView view, int imgResID) {
    Log.d("Utils", "Loadtexture");
    Bitmap img = null;
    int textures[] = new int[1];
    try {
      img = BitmapFactory.decodeResource(view.getResources(), imgResID);
      GLES20.glGenTextures(1, textures, 0);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
      GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, img, 0);
      Log.d("LoadTexture", "Loaded texture" + ":H:" + img.getHeight() + ":W:" + img.getWidth());
    } catch (Exception e) {
      Log.d("LoadTexture", e.toString() + ":" + e.getMessage() + ":" + e.getLocalizedMessage());
    }
    img.recycle();
    return textures[0];
  }
Ejemplo n.º 30
0
  public Texture(boolean shouldInterpolate, boolean shouldRepeat) {

    this.mInterpolate = shouldInterpolate;
    this.mRepeat = shouldRepeat;

    GLES20.glGenTextures(1, mTexId, 0);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, getTextureId());

    int repeatStrategy = mRepeat ? GLES20.GL_REPEAT : GLES20.GL_CLAMP_TO_EDGE;
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, repeatStrategy);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, repeatStrategy);

    // if you want that to be smoothly interpolated change GL_NEAREST to GL_LINEAR
    int interpStrategy = this.mInterpolate ? GLES20.GL_LINEAR : GLES20.GL_NEAREST;

    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, interpStrategy);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, interpStrategy);
  }