Package graphics
Class Texture
java.lang.Object
graphics.Texture
This is a class for an OpenGL texture
- Author:
- Asher Haun, VoxelRifts
-
Constructor Summary
ConstructorDescriptionTexture()
Texture
(int width, int height, TextureSpec spec) Load a Texture from a filepath. -
Method Summary
Modifier and TypeMethodDescriptionvoid
bind()
Bind this texture to the currently active texture slotvoid
bindToSlot
(int unit) Bind this texture to a specific texture slotcreateTexture
(int width, int height, ByteBuffer data) Creates a texture with specified width, height and data.void
delete()
The filepath from which this texture was loaded.int
Get This texture's height.int
Get the texture's id.int
getWidth()
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
Will write am OpenGL Texture to the provided filevoid
unbind()
Unbind the texturevoid
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
-
Constructor Details
-
Texture
public Texture() -
Texture
Load a Texture from a filepath. Recommended to use Assets.loadTexture instead of calling this function- Parameters:
filepath
- filepath of the texture
-
Texture
-
-
Method Details
-
toFile
Will write am OpenGL Texture to the provided file- Parameters:
file
- path where the image is to be stored with extensionid
- id of the OpenGL Texture Resourcewidth
- width of the textureheight
- height of the texture
-
uploadData
Uploads image data with specified width and height.- Parameters:
width
- Width of the imageheight
- Height of the imagedata
- Pixel data of the image
-
uploadData
Uploads image data with specified internal format, width, height and image format.- Parameters:
internalFormat
- Internal format of the image datawidth
- Width of the imageheight
- Height of the imageformat
- Format of the image datadata
- Pixel data of the image
-
createTexture
Creates a texture with specified width, height and data.- Parameters:
width
- Width of the textureheight
- Height of the texturedata
- 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 parametervalue
- Value to set
-
wrap
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
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()
-