Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Texture {
- int m_RendererID;
- String filePath;
- IntBuffer width, height, m_BPP;
- ByteBuffer image;
- public Texture(String filePath) {
- this.filePath = filePath;
- width = height = m_BPP = BufferUtils.createIntBuffer(1);
- this.image = stbi_load(filePath, width, height, m_BPP, 4);
- this.m_RendererID = glGenTextures();
- glBindTexture(GL_TEXTURE_2D, this.m_RendererID);
- 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);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width.get(0), height.get(0), 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
- unbind();
- if (this.image != null)
- stbi_image_free(this.image);
- else assert false: "Error: (Texture) Could not load image '" + filePath + "'";
- }
- void bind(int slot) {
- glActiveTexture(GL_TEXTURE0 + slot);
- glBindTexture(GL_TEXTURE_2D, this.m_RendererID);
- }
- void unbind() { glBindTexture(GL_TEXTURE_2D, 0); }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement