/** * Should be used to load image data from source. */ @Override public void load() { try { ByteBuffer byteBuffer = IOUtil.resourceToByteBuffer(getPath()); int[] width = {0}; int[] height = {0}; int[] channels = {0}; ByteBuffer imageData = STBImage.stbi_load_from_memory(byteBuffer, width, height, channels, 4); if (imageData != null) { this.width = width[0]; this.height = height[0]; this.channels = ImageChannels.instance(channels[0]); this.imageData = imageData; } else { // if error occurs throw LeguiExceptionTemplate.FAILED_TO_LOAD_IMAGE.create(STBImage.stbi_failure_reason()); } } catch (IOException e) { throw LeguiExceptionTemplate.FAILED_TO_LOAD_IMAGE.create(e, e.getMessage()); } }
ByteBuffer image = stbi_load_from_memory(imageBuffer, w, h, c, 0); if (image == null) { throw new RuntimeException("Failed to load image: " + stbi_failure_reason());
IntBuffer components = BufferUtils.createIntBuffer(1); ByteBuffer imageBuffer = stbi_load_from_memory((ByteBuffer) memory.nativeBuffer(), width, height, components, 4);
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
public Texture(ByteBuffer imageData) { try (MemoryStack stack = stackPush()) { IntBuffer w = stack.mallocInt(1); IntBuffer h = stack.mallocInt(1); IntBuffer avChannels = stack.mallocInt(1); // Decode texture image into a byte buffer ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); this.width = w.get(); this.height = h.get(); // Create a new OpenGL texture this.id = glGenTextures(); // Bind the texture glBindTexture(GL_TEXTURE_2D, this.id); // Tell OpenGL how to unpack the RGBA bytes. Each component is 1 byte size glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Upload the texture data glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, decodedImage); // Generate Mip Map glGenerateMipmap(GL_TEXTURE_2D); } }
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();
ByteBuffer decodedImage = stbi_load_from_memory(imageData, w, h, avChannels, 4); int width = w.get(); int height = h.get();