Beispiel #1
0
  public int loadCubeMap(String[] textures) {
    int textureID = GL11.glGenTextures();

    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, textureID);

    for (int i = 0; i < textures.length; i++) {
      TextureData data = decodeTextureFile("res/Textures/" + textures[i] + ".png");

      GL11.glTexImage2D(
          GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
          0,
          GL11.GL_RGBA,
          data.getWidth(),
          data.getHeight(),
          0,
          GL11.GL_RGBA,
          GL11.GL_UNSIGNED_BYTE,
          data.getBuffer());
    }

    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
    GL11.glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

    this.textures.add(textureID);

    return textureID;
  }
Beispiel #2
0
  private static void setupShadowRenderTexture() {
    if (shadowPassInterval <= 0) {
      return;
    }

    // depth
    glDeleteTextures(sfbDepthTexture);
    sfbDepthTexture = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, sfbDepthTexture);

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    ByteBuffer buffer = ByteBuffer.allocateDirect(shadowMapWidth * shadowMapHeight * 4);
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_DEPTH_COMPONENT,
        shadowMapWidth,
        shadowMapHeight,
        0,
        GL_DEPTH_COMPONENT,
        GL11.GL_FLOAT,
        buffer);
  }
  public Texture(String path) {

    try {
      BufferedImage image = ImageIO.read(new FileInputStream(path));
      width = image.getWidth();
      height = image.getHeight();
      pixels = new int[width * height];
      image.getRGB(0, 0, width, height, pixels, 0, width);
    } catch (IOException e) {
      e.printStackTrace();
    }
    int[] data = new int[width * height];
    for (int i = 0; i < data.length; i++) {
      int a = (pixels[i] & 0xff000000) >> 24;
      int r = (pixels[i] & 0xff0000) >> 16;
      int g = (pixels[i] & 0xff00) >> 8;
      int b = (pixels[i] & 0xff);
      data[i] = a << 24 | b << 16 | g << 8 | r;
    }
    int id = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, id);

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

    IntBuffer buffer = (IntBuffer) BufferUtils.createIntBuffer(data.length).put(data).flip();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    this.index = id;
    glBindTexture(GL_TEXTURE_2D, 0);
  }
Beispiel #4
0
  private int loadTexture() {
    try {
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      ImageIO.write(asBufferedImage, "png", os);

      int textureID = GL11.glGenTextures(); // Generate texture ID
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID); // Bind texture ID

      // Setup texture scaling filtering
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

      // Send texel data to OpenGL
      GL11.glTexImage2D(
          GL11.GL_TEXTURE_2D,
          0,
          GL11.GL_RGBA8,
          asBufferedImage.getWidth(),
          asBufferedImage.getHeight(),
          0,
          GL11.GL_RGBA,
          GL11.GL_UNSIGNED_BYTE,
          asByteBuffer);

      // Return the texture ID so we can bind it later again
      return textureID;

    } catch (IOException e) {
      e.printStackTrace();
    }
    return 0;
  }
  /** Copy the supplied image onto the specified OpenGL texture */
  public void setupTexture(BufferedImage par1BufferedImage, int par2) {
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, par2);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

    if (this.blurTexture) {
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    }

    if (this.clampTexture) {
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    } else {
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    }

    int var3 = par1BufferedImage.getWidth();
    int var4 = par1BufferedImage.getHeight();
    int[] var5 = new int[var3 * var4];
    byte[] var6 = new byte[var3 * var4 * 4];
    par1BufferedImage.getRGB(0, 0, var3, var4, var5, 0, var3);

    for (int var7 = 0; var7 < var5.length; ++var7) {
      int var8 = var5[var7] >> 24 & 255;
      int var9 = var5[var7] >> 16 & 255;
      int var10 = var5[var7] >> 8 & 255;
      int var11 = var5[var7] & 255;

      if (this.options != null && this.options.anaglyph) {
        int var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
        int var13 = (var9 * 30 + var10 * 70) / 100;
        int var14 = (var9 * 30 + var11 * 70) / 100;
        var9 = var12;
        var10 = var13;
        var11 = var14;
      }

      var6[var7 * 4 + 0] = (byte) var9;
      var6[var7 * 4 + 1] = (byte) var10;
      var6[var7 * 4 + 2] = (byte) var11;
      var6[var7 * 4 + 3] = (byte) var8;
    }

    this.imageData.clear();
    this.imageData.put(var6);
    this.imageData.position(0).limit(var6.length);
    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        GL11.GL_RGBA,
        var3,
        var4,
        0,
        GL11.GL_RGBA,
        GL11.GL_UNSIGNED_BYTE,
        this.imageData);
  }
Beispiel #6
0
  // Load an image from file.
  private int load(String path) {
    int[] pixels = null;
    try {
      BufferedImage image = ImageIO.read(new FileInputStream(path));
      width = image.getWidth();
      height = image.getHeight();
      pixels = new int[width * height];

      image.getRGB(0, 0, width, width, pixels, 0, width);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Rearrange the data from ARGB to RGBA.
    int[] data = new int[width * height];
    for (int i = 0; i < width * height; i++) {
      // Separate the colour channels.
      int a = (pixels[i] & 0xff000000) >> 24;
      int r = (pixels[i] & 0x00ff0000) >> 16;
      int g = (pixels[i] & 0x0000ff00) >> 8;
      int b = (pixels[i] & 0x000000ff);

      // Convert from ARGB to ABGR.
      data[i] = a << 24 | b << 16 | g << 8 | r;
    }

    //
    int result = glGenTextures();

    // "Select" the texture to allow changes.
    glBindTexture(GL_TEXTURE_2D, result);

    // Use nearest-neighbour instead of blending when we upscale.
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // Enable transparency.
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA,
        width,
        height,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        BufferUtils.createIntBuffer(data));

    // Deselect everything.
    glBindTexture(GL_TEXTURE_2D, 0);

    return result;
  }
 private static void makeRGBTexture(
     ByteBuffer img, int width, int height, boolean storeAlphaChannel) {
   int components = storeAlphaChannel ? 4 : 3;
   int format = storeAlphaChannel ? GL11.GL_RGBA : GL11.GL_RGB;
   GL11.glTexImage2D(
       GL11.GL_TEXTURE_2D, 0, components, width, height, 0, format, GL11.GL_UNSIGNED_BYTE, img);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
   GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
   GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
 }
Beispiel #8
0
  private static TextureResource loadTexture(String fileName) {
    String[] splitArray = fileName.split("\\.");
    String ext = splitArray[splitArray.length - 1];

    try {
      BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName));
      int[] pixels =
          image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());

      ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4);
      boolean hasAlpha = image.getColorModel().hasAlpha();

      for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
          int pixel = pixels[y * image.getWidth() + x];

          buffer.put((byte) ((pixel >> 16) & 0xFF));
          buffer.put((byte) ((pixel >> 8) & 0xFF));
          buffer.put((byte) ((pixel) & 0xFF));
          if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF));
          else buffer.put((byte) (0xFF));
        }
      }

      buffer.flip();

      TextureResource resource = new TextureResource();
      glBindTexture(GL_TEXTURE_2D, resource.getId());

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

      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

      glTexImage2D(
          GL_TEXTURE_2D,
          0,
          GL_RGBA8,
          image.getWidth(),
          image.getHeight(),
          0,
          GL_RGBA,
          GL_UNSIGNED_BYTE,
          buffer);

      return resource;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

    return null;
  }
Beispiel #9
0
  public static ArrayList<Texture> getTileSet(
      String resourceName,
      int x,
      int y,
      int target,
      int dstPixelFormat,
      int minFilter,
      int magFilter)
      throws IOException {
    int srcPixelFormat;

    ArrayList<BufferedImage> images = loadImage(resourceName, x, y);
    ArrayList<Texture> textures = new ArrayList<Texture>();
    for (int i = 0; i < x * y; i++) {
      // create the texture ID for this texture
      int textureID = createTextureID();
      textures.add(i, new Texture(target, textureID));
      // bind this texture
      glBindTexture(target, textureID);

      BufferedImage bufferedImage = images.get(i);
      textures.get(i).setWidth(bufferedImage.getWidth());
      textures.get(i).setHeight(bufferedImage.getHeight());

      if (bufferedImage.getColorModel().hasAlpha()) {
        srcPixelFormat = GL_RGBA;
      } else {
        srcPixelFormat = GL_RGB;
      }

      // convert that image into a byte buffer of texture data
      ByteBuffer textureBuffer = convertImageData(bufferedImage, textures.get(i));

      if (target == GL_TEXTURE_2D) {
        glTexParameteri(target, GL_TEXTURE_MIN_FILTER, minFilter);
        glTexParameteri(target, GL_TEXTURE_MAG_FILTER, magFilter);
      }

      // produce a texture from the byte buffer
      glTexImage2D(
          target,
          0,
          dstPixelFormat,
          get2Fold(bufferedImage.getWidth()),
          get2Fold(bufferedImage.getHeight()),
          0,
          srcPixelFormat,
          GL_UNSIGNED_BYTE,
          textureBuffer);
    }

    return textures;
  }
  public Texture(URI pngRef, int filter, int wrap) throws IOException {
    InputStream input = null;
    try {
      // get an InputStream from our URL
      input = pngRef.toURL().openStream();

      // initialize the decoder
      PNGDecoder dec = new PNGDecoder(input);

      // set up image dimensions
      width = dec.getWidth();
      height = dec.getHeight();

      // we are using RGBA, i.e. 4 components or "bytes per pixel"
      final int bpp = 4;

      // create a new byte buffer which will hold our pixel data
      ByteBuffer buf = BufferUtils.createByteBuffer(bpp * width * height);

      // decode the image into the byte buffer, in RGBA format
      dec.decode(buf, width * bpp, PNGDecoder.Format.RGBA);

      // flip the buffer into "read mode" for OpenGL
      buf.flip();

      // enable textures and generate an ID
      glEnable(target);
      id = glGenTextures();

      // bind texture
      bind();

      // setup unpack mode
      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

      // setup parameters
      glTexParameteri(target, GL_TEXTURE_MIN_FILTER, filter);
      glTexParameteri(target, GL_TEXTURE_MAG_FILTER, filter);
      glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap);
      glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap);

      // pass RGBA data to OpenGL
      glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
    } finally {
      if (input != null) {
        try {
          input.close();
        } catch (IOException e) {
        }
      }
    }
  }
Beispiel #11
0
  private static void setupRenderTextures() {
    glDeleteTextures(dfbTextures);
    glGenTextures(dfbTextures);

    for (int i = 0; i < colorAttachments; ++i) {
      glBindTexture(GL_TEXTURE_2D, dfbTextures.get(i));
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
      if (i == 1) { // depth buffer
        ByteBuffer buffer = ByteBuffer.allocateDirect(renderWidth * renderHeight * 4 * 4);
        glTexImage2D(
            GL_TEXTURE_2D,
            0,
            GL_RGB32F_ARB,
            renderWidth,
            renderHeight,
            0,
            GL_RGBA,
            GL11.GL_FLOAT,
            buffer);
      } else {
        ByteBuffer buffer = ByteBuffer.allocateDirect(renderWidth * renderHeight * 4);
        glTexImage2D(
            GL_TEXTURE_2D,
            0,
            GL_RGBA,
            renderWidth,
            renderHeight,
            0,
            GL_RGBA,
            GL_UNSIGNED_BYTE,
            buffer);
      }
    }
  }
  public void func_110379_a(BufferedImage var1, int var2) {
    GL11.glBindTexture(3553, var2);
    GL11.glTexParameteri(3553, 10241, 9728);
    GL11.glTexParameteri(3553, 10240, 9728);
    if (this.field_110389_b) {
      GL11.glTexParameteri(3553, 10241, 9729);
      GL11.glTexParameteri(3553, 10240, 9729);
    }

    if (this.field_110391_a) {
      GL11.glTexParameteri(3553, 10242, 10496);
      GL11.glTexParameteri(3553, 10243, 10496);
    } else {
      GL11.glTexParameteri(3553, 10242, 10497);
      GL11.glTexParameteri(3553, 10243, 10497);
    }

    int var3 = var1.getWidth();
    int var4 = var1.getHeight();
    int[] var5 = new int[var3 * var4];
    byte[] var6 = new byte[var3 * var4 * 4];
    var1.getRGB(0, 0, var3, var4, var5, 0, var3);

    for (int var7 = 0; var7 < var5.length; ++var7) {
      int var8 = var5[var7] >> 24 & 255;
      int var9 = var5[var7] >> 16 & 255;
      int var10 = var5[var7] >> 8 & 255;
      int var11 = var5[var7] & 255;
      if (this.field_110393_j != null && this.field_110393_j.field_111716_g) {
        int var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
        int var13 = (var9 * 30 + var10 * 70) / 100;
        int var14 = (var9 * 30 + var11 * 70) / 100;
        var9 = var12;
        var10 = var13;
        var11 = var14;
      }

      var6[var7 * 4 + 0] = (byte) var9;
      var6[var7 * 4 + 1] = (byte) var10;
      var6[var7 * 4 + 2] = (byte) var11;
      var6[var7 * 4 + 3] = (byte) var8;
    }

    this.field_110386_g.clear();
    this.field_110386_g.put(var6);
    this.field_110386_g.position(0).limit(var6.length);
    GL11.glTexImage2D(3553, 0, 6408, var3, var4, 0, 6408, 5121, this.field_110386_g);
  }
  /**
   * <code>setupTexture</code> initializes a new Texture object for use with TextureRenderer.
   * Generates a valid gl texture id for this texture and inits the data type for the texture.
   */
  public void setupTexture(final Texture tex) {
    if (tex.getType() != Type.TwoDimensional) {
      throw new IllegalArgumentException("Unsupported type: " + tex.getType());
    }
    final RenderContext context = ContextManager.getCurrentContext();
    final TextureStateRecord record =
        (TextureStateRecord) context.getStateRecord(RenderState.StateType.Texture);

    // check if we are already setup... if so, throw error.
    if (tex.getTextureKey() == null) {
      tex.setTextureKey(TextureKey.getRTTKey(tex.getMinificationFilter()));
    } else if (tex.getTextureIdForContext(context.getGlContextRep()) != 0) {
      throw new Ardor3dException("Texture is already setup and has id.");
    }

    // Create the texture
    final IntBuffer ibuf = BufferUtils.createIntBuffer(1);
    GL11.glGenTextures(ibuf);
    final int textureId = ibuf.get(0);
    tex.setTextureIdForContext(context.getGlContextRep(), textureId);

    LwjglTextureStateUtil.doTextureBind(tex, 0, true);

    // Initialize our texture with some default data.
    final int internalFormat = LwjglTextureUtil.getGLInternalFormat(tex.getTextureStoreFormat());
    final int dataFormat =
        LwjglTextureUtil.getGLPixelFormatFromStoreFormat(tex.getTextureStoreFormat());
    final int pixelDataType =
        LwjglTextureUtil.getGLPixelDataType(tex.getRenderedTexturePixelDataType());

    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        internalFormat,
        _width,
        _height,
        0,
        dataFormat,
        pixelDataType,
        (ByteBuffer) null);

    // Setup filtering and wrap
    final TextureRecord texRecord = record.getTextureRecord(textureId, tex.getType());
    LwjglTextureStateUtil.applyFilter(tex, texRecord, 0, record, context.getCapabilities());
    LwjglTextureStateUtil.applyWrap(tex, texRecord, 0, record, context.getCapabilities());

    logger.fine("setup pbuffer tex" + textureId + ": " + _width + "," + _height);
  }
  public GLImage(String _filename) {
    try {
      BufferedImage image = ImageIO.read(this.getClass().getResource("/textures/" + _filename));
      int[] pixels = new int[image.getWidth() * image.getHeight()];
      image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
      ByteBuffer buffer =
          BufferUtils.createByteBuffer(
              image.getWidth() * image.getHeight() * 4); // 4 for RGBA, 3 for RGB
      for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
          int pixel = pixels[y * image.getWidth() + x];
          buffer.put((byte) ((pixel >> 16) & 0xFF)); // red
          buffer.put((byte) ((pixel >> 8) & 0xFF)); // green
          buffer.put((byte) (pixel & 0xFF)); // blue
          buffer.put((byte) ((pixel >> 24) & 0xFF)); // alpha
        }
      }
      buffer.flip();

      this.id = GL11.glGenTextures(); // Generate texture ID
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.id); // Bind texture ID
      // Setup wrap mode
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
      // Setup texture scaling filtering
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
      // Send texel data to OpenGL
      GL11.glTexImage2D(
          GL11.GL_TEXTURE_2D,
          0,
          GL11.GL_RGBA8,
          image.getWidth(),
          image.getHeight(),
          0,
          GL11.GL_RGBA,
          GL11.GL_UNSIGNED_BYTE,
          buffer);

      this.width = image.getWidth();
      this.height = image.getHeight();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #15
0
  private int load(String path) {
    int[] pixels;
    try {
      BufferedImage image = ImageIO.read(new FileInputStream(path));
      width = image.getWidth();
      height = image.getHeight();
      pixels = new int[width * height];
      image.getRGB(0, 0, width, height, pixels, 0, width);
    } catch (IOException e) {
      e.printStackTrace();
      return -1;
    }

    int[] data = new int[pixels.length];
    for (int i = 0; i < data.length; i++) {
      int alpha = (pixels[i] & 0xFF000000) >> 24;
      int red = (pixels[i] & 0xff0000) >> 16;
      int green = (pixels[i] & 0xff00) >> 8;
      int blue = (pixels[i] & 0xff);

      data[i] = alpha << 24 | blue << 16 | green << 8 | red;
    }

    int result = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, result);

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

    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA,
        width,
        height,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        Utilities.createIntBuffer(data));

    glBindTexture(GL_TEXTURE_2D, 0);

    return result;
  }
Beispiel #16
0
    private void recreate() {
      id = GL11.glGenTextures();

      GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, format.bytes);

      ByteBuffer data =
          BufferUtils.createByteBuffer(size.getWidth() * size.getHeight() * format.bytes);

      if (mipmap) {
        GLU.gluBuild2DMipmaps(
            GL11.GL_TEXTURE_2D,
            format.glInternalFormat,
            size.getWidth(),
            size.getHeight(),
            format.glFormat,
            GL11.GL_UNSIGNED_BYTE,
            data);
      } else {
        GL11.glTexImage2D(
            GL11.GL_TEXTURE_2D,
            0,
            format.glInternalFormat,
            size.getWidth(),
            size.getHeight(),
            0,
            format.glFormat,
            GL11.GL_UNSIGNED_BYTE,
            data);
      }
      GLUtil.checkGLError();

      for (Texture t : residentTextures) {
        RectanglePacker.Rectangle rpr = packer.findRectangle(t.getSourceImage());

        if (rpr != null) {
          writeToTexture(rpr, t.getSourceImage().getData());
        }
      }

      regenerateMipmaps();
    }
Beispiel #17
0
  /**
   * The constructor that creates the font from the given file at the given height.
   *
   * @param filePath - The path to file including the file type
   * @param fontHeight - The height (size) of the font
   */
  public TrueTypeFont(String filePath, int fontHeight) {
    this.fontHeight = fontHeight;

    long startTime = 0L;
    if (Debug.enabled) startTime = System.nanoTime();

    textureID = glGenTextures();
    cdata = STBTTBakedChar.mallocBuffer(96);

    try {
      ByteBuffer ttf = IOUtil.ioResourceToByteBuffer(filePath, 160 * 1024);

      ByteBuffer bitmap = BufferUtils.createByteBuffer(BITMAP_W * BITMAP_H);
      STBTruetype.stbtt_BakeFontBitmap(ttf, fontHeight, bitmap, BITMAP_W, BITMAP_H, 32, cdata);

      glBindTexture(GL_TEXTURE_2D, textureID);
      glTexImage2D(
          GL_TEXTURE_2D, 0, GL_ALPHA, BITMAP_W, BITMAP_H, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }

    xbuf = BufferUtils.createFloatBuffer(1);
    ybuf = BufferUtils.createFloatBuffer(1);
    quad = STBTTAlignedQuad.malloc();

    if (Debug.enabled) {
      long endTime = System.nanoTime();
      Debug.println(
          " Loaded font: "
              + filePath
              + "\n\tFont height: "
              + fontHeight
              + "px"
              + "\n\tLoad time: "
              + Debug.noNotation.format((endTime - startTime) / 1000000000.0)
              + "s",
          Debug.ANSI_CYAN);
    }
  }
Beispiel #18
0
  private void initGLObjects() {
    if (clTexture != NULL) {
      checkCLError(clReleaseMemObject(clTexture));
      glDeleteTextures(glTexture);
    }

    glTexture = glGenTextures();

    // Init textures
    glBindTexture(GL_TEXTURE_2D, glTexture);
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA8UI,
        ww,
        wh,
        0,
        GL_RGBA_INTEGER,
        GL_UNSIGNED_BYTE,
        (ByteBuffer) null);

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

    clTexture =
        clCreateFromGLTexture2D(
            clContext, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, glTexture, errcode_ret);
    checkCLError(errcode_ret);
    glBindTexture(GL_TEXTURE_2D, 0);

    glViewport(0, 0, fbw, fbh);

    glUniform2f(sizeUniform, ww, wh);

    FloatBuffer projectionMatrix = BufferUtils.createFloatBuffer(4 * 4);
    glOrtho(0.0f, ww, 0.0f, wh, 0.0f, 1.0f, projectionMatrix);
    glUniformMatrix4fv(projectionUniform, false, projectionMatrix);

    shouldInitBuffers = false;
  }
  public BufferTexture(BufferedImage image) {
    int[] pixels = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());

    ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);

    for (int y = 0; y < image.getHeight(); y++) {
      for (int x = 0; x < image.getWidth(); x++) {
        int pixel = pixels[(y * image.getWidth()) + x];
        buffer.put((byte) ((pixel >> 16) & 0xFF));
        buffer.put((byte) ((pixel >> 8) & 0xFF));
        buffer.put((byte) (pixel & 0xFF));
        buffer.put((byte) ((pixel >> 24) & 0xFF));
      }
    }

    buffer.flip();

    this.width = image.getWidth();
    this.height = image.getHeight();

    this.textureId = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.textureId);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
    GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        GL11.GL_RGBA8,
        this.width,
        this.height,
        0,
        GL11.GL_RGBA,
        GL11.GL_UNSIGNED_BYTE,
        buffer);
  }
Beispiel #20
0
 public void glTexImage2D(
     int target,
     int level,
     int internalformat,
     int width,
     int height,
     int border,
     int format,
     int type,
     Buffer pixels) {
   if (pixels == null)
     GL11.glTexImage2D(
         target, level, internalformat, width, height, border, format, type, (ByteBuffer) null);
   else if (pixels instanceof ByteBuffer)
     GL11.glTexImage2D(
         target, level, internalformat, width, height, border, format, type, (ByteBuffer) pixels);
   else if (pixels instanceof ShortBuffer)
     GL11.glTexImage2D(
         target, level, internalformat, width, height, border, format, type, (ShortBuffer) pixels);
   else if (pixels instanceof IntBuffer)
     GL11.glTexImage2D(
         target, level, internalformat, width, height, border, format, type, (IntBuffer) pixels);
   else if (pixels instanceof FloatBuffer)
     GL11.glTexImage2D(
         target, level, internalformat, width, height, border, format, type, (FloatBuffer) pixels);
   else if (pixels instanceof DoubleBuffer)
     GL11.glTexImage2D(
         target,
         level,
         internalformat,
         width,
         height,
         border,
         format,
         type,
         (DoubleBuffer) pixels);
   else
     throw new GdxRuntimeException(
         "Can't use "
             + pixels.getClass().getName()
             + " with this method. Use ByteBuffer, ShortBuffer, IntBuffer, FloatBuffer or DoubleBuffer instead. Blame LWJGL");
 }
  public static UIFont createGuiFont(String name, int font_size) {
    Font font = load_ttf(StringUtils.concat(name, ".ttf"), font_size);
    UIFont tmp = new UIFont();

    tmp.font_texture = new Texture();

    Graphics2D graphics = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB).createGraphics();
    graphics.setFont(font);

    tmp.fontMetrics = graphics.getFontMetrics();

    WritableRaster raster;
    BufferedImage bufferedImage;

    raster =
        Raster.createInterleavedRaster(
            DataBuffer.TYPE_BYTE,
            (int) tmp.getFontImageWidth(),
            (int) tmp.getFontImageHeight(),
            4,
            null);
    bufferedImage = new BufferedImage(glAlphaColorModel, raster, false, null);

    // Draw the characters on our image
    Graphics2D imageGraphics = bufferedImage.createGraphics();
    imageGraphics.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    imageGraphics.setRenderingHint(
        RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    imageGraphics.setFont(font);
    imageGraphics.setColor(Color.white.getAWTColor());

    // draw every CHAR by line...
    for (int i : key_table.keySet())
      imageGraphics.drawString(
          key_table.get(i), 0, (int) (tmp.fontMetrics.getMaxAscent() + (tmp.getHeight() * i)));

    // Generate texture data
    byte[] data = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();

    ByteBuffer imageData = BufferUtils.create_byte_buffer(data.length);
    imageData.order(ByteOrder.nativeOrder());
    imageData.put(data, 0, data.length);
    imageData.flip();

    glBindTexture(GL_TEXTURE_2D, tmp.font_texture.id);

    // Setup wrap mode
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

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

    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA8,
        (int) tmp.getFontImageWidth(),
        (int) tmp.getFontImageHeight(),
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        imageData);

    return tmp;
  }
Beispiel #22
0
  public void load() {

    glBindTexture(GL13.GL_TEXTURE_CUBE_MAP, ID);

    // Setup texture scaling filtering
    glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL13.GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    int w = getWidth();
    int h = getHeight();
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[0]);
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[1]);
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[2]);
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[3]);
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[4]);
    glTexImage2D(
        GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
        0,
        GL_RGBA8,
        w,
        h,
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        data[5]);
  }
Beispiel #23
0
  public DynamicImage createDynamicImage(int width, int height) {
    if (width <= 0) {
      throw new IllegalArgumentException("width");
    }
    if (height <= 0) {
      throw new IllegalArgumentException("height");
    }
    if (width > maxTextureSize || height > maxTextureSize) {
      getLogger()
          .log(
              Level.WARNING,
              "requested size {0} x {1} exceeds maximum texture size {3}",
              new Object[] {width, height, maxTextureSize});
      return null;
    }

    int texWidth = width;
    int texHeight = height;

    ContextCapabilities caps = GLContext.getCapabilities();
    boolean useTextureRectangle = caps.GL_EXT_texture_rectangle || caps.GL_ARB_texture_rectangle;

    if (!useTextureRectangle && !caps.GL_ARB_texture_non_power_of_two) {
      texWidth = nextPowerOf2(width);
      texHeight = nextPowerOf2(height);
    }

    // ARB and EXT versions use the same enum !
    int proxyTarget =
        useTextureRectangle
            ? EXTTextureRectangle.GL_PROXY_TEXTURE_RECTANGLE_EXT
            : GL11.GL_PROXY_TEXTURE_2D;

    GL11.glTexImage2D(
        proxyTarget,
        0,
        GL11.GL_RGBA,
        texWidth,
        texHeight,
        0,
        GL11.GL_RGBA,
        GL11.GL_UNSIGNED_BYTE,
        (ByteBuffer) null);
    ib16.clear();
    GL11.glGetTexLevelParameter(proxyTarget, 0, GL11.GL_TEXTURE_WIDTH, ib16);
    if (ib16.get(0) != texWidth) {
      getLogger()
          .log(
              Level.WARNING,
              "requested size {0} x {1} failed proxy texture test",
              new Object[] {texWidth, texHeight});
      return null;
    }

    // ARB and EXT versions use the same enum !
    int target =
        useTextureRectangle ? EXTTextureRectangle.GL_TEXTURE_RECTANGLE_EXT : GL11.GL_TEXTURE_2D;
    int id = GL11.glGenTextures();

    GL11.glBindTexture(target, id);
    GL11.glTexImage2D(
        target,
        0,
        GL11.GL_RGBA,
        texWidth,
        texHeight,
        0,
        GL11.GL_RGBA,
        GL11.GL_UNSIGNED_BYTE,
        (ByteBuffer) null);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(target, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);

    LWJGLDynamicImage image =
        new LWJGLDynamicImage(this, target, id, width, height, texWidth, texHeight, Color.WHITE);
    dynamicImages.add(image);
    return image;
  }
Beispiel #24
0
  /**
   * Loads a texture from a file.
   *
   * @param name The name of the file.
   */
  public static Texture loadTexture(String name) {
    // Load the image
    bimg = null;
    try {
      bimg = ImageIO.read(new File(name));
    } catch (IOException e) {
      e.printStackTrace();
      System.out.println("Unable to load Texture: " + name);
    }

    // Gather all the pixels
    int[] pixels = new int[bimg.getWidth() * bimg.getHeight()];
    bimg.getRGB(0, 0, bimg.getWidth(), bimg.getHeight(), pixels, 0, bimg.getWidth());

    // Create a ByteBuffer
    ByteBuffer buffer = BufferUtils.createByteBuffer(bimg.getWidth() * bimg.getHeight() * 4);

    // Iterate through all the pixels and add them to the ByteBuffer
    for (int y = 0; y < bimg.getHeight(); y++) {
      for (int x = 0; x < bimg.getWidth(); x++) {
        // Select the pixel
        int pixel = pixels[y * bimg.getWidth() + x];
        // Add the RED component
        buffer.put((byte) ((pixel >> 16) & 0xFF));
        // Add the GREEN component
        buffer.put((byte) ((pixel >> 8) & 0xFF));
        // Add the BLUE component
        buffer.put((byte) (pixel & 0xFF));
        // Add the ALPHA component
        buffer.put((byte) ((pixel >> 24) & 0xFF));
      }
    }

    // Reset the read location in the buffer so that GL can read from
    // beginning.
    buffer.flip();

    // Generate a texture ID
    int textureID = glGenTextures();
    // Bind the ID to the context
    glBindTexture(GL_TEXTURE_2D, textureID);

    // Setup texture scaling filtering
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    // Send texture data to OpenGL
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGBA8,
        bimg.getWidth(),
        bimg.getHeight(),
        0,
        GL_RGBA,
        GL_UNSIGNED_BYTE,
        buffer);

    // Return a new Texture.
    return new Texture(textureID, bimg.getWidth(), bimg.getHeight());
  }
  @Override
  public void writeGPU() {
    if (framebuffer != INVALID_BUFFER)
      throw new IllegalStateException("Framebuffer already created!");

    // Create the color buffer for this renderTexture
    textureID = GL11.glGenTextures();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
    GL11.glTexImage2D(
        GL11.GL_TEXTURE_2D,
        0,
        GL11.GL_RGBA8,
        width,
        height,
        0,
        GL11.GL_RGBA,
        GL11.GL_INT,
        (java.nio.ByteBuffer) null); // Create the texture data

    if (useEXT) {
      framebuffer = EXTFramebufferObject.glGenFramebuffersEXT();

      EXTFramebufferObject.glBindFramebufferEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT, framebuffer);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

      EXTFramebufferObject.glFramebufferTexture2DEXT(
          EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
          EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT,
          GL11.GL_TEXTURE_2D,
          textureID,
          0);

      if (useDepthBuffer) {
        depthTarget = GL30.glGenRenderbuffers();
        EXTFramebufferObject.glBindRenderbufferEXT(
            EXTFramebufferObject.GL_RENDERBUFFER_EXT, depthTarget);
        EXTFramebufferObject.glRenderbufferStorageEXT(
            EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            GL11.GL_DEPTH_COMPONENT,
            this.getWidth(),
            this.getHeight());
        EXTFramebufferObject.glFramebufferRenderbufferEXT(
            EXTFramebufferObject.GL_FRAMEBUFFER_EXT,
            GL30.GL_DEPTH_ATTACHMENT,
            EXTFramebufferObject.GL_RENDERBUFFER_EXT,
            depthTarget);
      }

      if (EXTFramebufferObject.glCheckFramebufferStatusEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT)
          != EXTFramebufferObject.GL_FRAMEBUFFER_COMPLETE_EXT) {
        System.out.println("ERROR: Framebuffer not complete");
        throw new ComputerIsPotatoException("Framebuffer not complete");
      }

    } else {
      framebuffer = GL30.glGenFramebuffers();
      GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, framebuffer);
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);

      GL30.glFramebufferTexture2D(
          GL30.GL_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL11.GL_TEXTURE_2D, textureID, 0);

      if (useDepthBuffer) {
        depthTarget = GL30.glGenRenderbuffers();
        GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthTarget);
        GL30.glRenderbufferStorage(
            GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, this.getWidth(), this.getHeight());
        GL30.glFramebufferRenderbuffer(
            GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthTarget);
      }
      GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, SCREEN_BUFFER);

      if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) {
        System.out.println("ERROR: Framebuffer not complete");
        throw new ComputerIsPotatoException("Framebuffer not complete");
      }
    }
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
  }
Beispiel #26
0
  /** Copy the supplied image onto the specified OpenGL texture */
  public void setupTexture(BufferedImage par1BufferedImage, int par2) {
    if (par1BufferedImage != null) { // Spout HD
      GL11.glBindTexture(GL11.GL_TEXTURE_2D, par2);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);

      if (this.blurTexture) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
      }

      if (this.clampTexture) {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
      } else {
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
      }

      // Spout Start
      int textureWidth = par1BufferedImage.getWidth();
      int textureHeight = par1BufferedImage.getHeight();
      int[] texData = new int[textureWidth * textureHeight];
      byte[] texColors = new byte[textureWidth * textureHeight * 4];
      // Performance reasons
      boolean handled = false;
      try {
        java.awt.image.DataBuffer buf = par1BufferedImage.getRaster().getDataBuffer();
        if (buf instanceof java.awt.image.DataBufferInt) {
          int[] srcbuf = ((java.awt.image.DataBufferInt) buf).getData();
          System.arraycopy(srcbuf, 0, texData, 0, srcbuf.length);
          handled = true;
        }
      } catch (Exception ignore) {
      }
      if (!handled) {
        par1BufferedImage.getRGB(0, 0, textureWidth, textureHeight, texData, 0, textureWidth);
      }

      int var8;
      int var9;
      int var10;
      int var11;
      int var12;
      int var13;
      int var14;

      for (int var7 = 0; var7 < texData.length; ++var7) {
        var8 = texData[var7] >> 24 & 255;
        var9 = texData[var7] >> 16 & 255;
        var10 = texData[var7] >> 8 & 255;
        var11 = texData[var7] & 255;

        if (this.options != null && this.options.anaglyph) {
          var12 = (var9 * 30 + var10 * 59 + var11 * 11) / 100;
          var13 = (var9 * 30 + var10 * 70) / 100;
          var14 = (var9 * 30 + var11 * 70) / 100;
          var9 = var12;
          var10 = var13;
          var11 = var14;
        }

        texColors[var7 * 4 + 0] = (byte) var9;
        texColors[var7 * 4 + 1] = (byte) var10;
        texColors[var7 * 4 + 2] = (byte) var11;
        texColors[var7 * 4 + 3] = (byte) var8;
      }
      // Spout End

      this.imageData = TextureUtils.getByteBuffer(this.imageData, texColors);
      GL11.glTexImage2D(
          GL11.GL_TEXTURE_2D,
          0,
          GL11.GL_RGBA,
          textureWidth,
          textureHeight,
          0,
          GL11.GL_RGBA,
          GL11.GL_UNSIGNED_BYTE,
          this.imageData);
    }
    // Spout HD End
  }