Package graphics

Class Texture

java.lang.Object
graphics.Texture

public class Texture extends Object
This is a class for an OpenGL texture
Author:
Asher Haun, VoxelRifts
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Texture(int width, int height, TextureSpec spec)
     
    Texture(String filepath)
    Load a Texture from a filepath.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Bind this texture to the currently active texture slot
    void
    bindToSlot(int unit)
    Bind this texture to a specific texture slot
    createTexture(int width, int height, ByteBuffer data)
    Creates a texture with specified width, height and data.
    void
     
    The filepath from which this texture was loaded.
    int
    Get This texture's height.
    int
    Get the texture's id.
    int
    Get This texture's width.
    void
    setHeight(int height)
     
    void
    setId(int id)
     
    void
    setParameter(int name, int value)
    Sets a parameter of the texture.
    void
    setWidth(int width)
     
    static void
    toFile(String file, int id, int width, int height)
    Will write am OpenGL Texture to the provided file
    void
    Unbind the texture
    void
    uploadData(int internalFormat, int width, int height, int format, ByteBuffer data)
    Uploads image data with specified internal format, width, height and image format.
    void
    uploadData(int width, int height, ByteBuffer data)
    Uploads image data with specified width and height.
    static Texture
    wrap(int id)
    Wrap the given id into a texture object

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Texture

      public Texture()
    • Texture

      public Texture(String filepath)
      Load a Texture from a filepath. Recommended to use Assets.loadTexture instead of calling this function
      Parameters:
      filepath - filepath of the texture
    • Texture

      public Texture(int width, int height, TextureSpec spec)
  • Method Details

    • toFile

      public static void toFile(String file, int id, int width, int height)
      Will write am OpenGL Texture to the provided file
      Parameters:
      file - path where the image is to be stored with extension
      id - id of the OpenGL Texture Resource
      width - width of the texture
      height - height of the texture
    • uploadData

      public void uploadData(int width, int height, ByteBuffer data)
      Uploads image data with specified width and height.
      Parameters:
      width - Width of the image
      height - Height of the image
      data - Pixel data of the image
    • uploadData

      public void uploadData(int internalFormat, int width, int height, int format, ByteBuffer data)
      Uploads image data with specified internal format, width, height and image format.
      Parameters:
      internalFormat - Internal format of the image data
      width - Width of the image
      height - Height of the image
      format - Format of the image data
      data - Pixel data of the image
    • createTexture

      public Texture createTexture(int width, int height, ByteBuffer data)
      Creates a texture with specified width, height and data.
      Parameters:
      width - Width of the texture
      height - Height of the texture
      data - Picture Data in RGBA format
      Returns:
      Texture from the specified data
    • setParameter

      public void setParameter(int name, int value)
      Sets a parameter of the texture.
      Parameters:
      name - Name of the parameter
      value - Value to set
    • wrap

      public static Texture wrap(int id)
      Wrap the given id into a texture object
      Parameters:
      id - the id to be wrapped
      Returns:
      the texture instance
    • bind

      public void bind()
      Bind this texture to the currently active texture slot
    • bindToSlot

      public void bindToSlot(int unit)
      Bind this texture to a specific texture slot
      Parameters:
      unit - the texture unit to bind this texture to
    • unbind

      public void unbind()
      Unbind the texture
    • getWidth

      public int getWidth()
      Get This texture's width. Will be -1 if the instance is just a wrapper
      Returns:
      the width of the texture
    • getHeight

      public int getHeight()
      Get This texture's height. Will be -1 if the instance is just a wrapper
      Returns:
      the height of the texture
    • setWidth

      public void setWidth(int width)
    • setHeight

      public void setHeight(int height)
    • getTextureID

      public int getTextureID()
      Get the texture's id.
      Returns:
      the id of the texture
    • getFilePath

      public String getFilePath()
      The filepath from which this texture was loaded. Will return "==== Wrapper ====" if it is just a wrapper around an id.
      Returns:
      filepath from which the texture was loaded
    • setId

      public void setId(int id)
    • delete

      public void delete()