# STBImage Very naive bindings for `stb_image.h`. Implements only `stbi_set_flip_vertically_on_load` and `stb_load` since these are the 2 functions I need to load an image as a texture in OpenGL. The reason I made this instead of using [stb-image](https://rubygems.org/gems/stb-image) is because stb-image didn't implement `stbi_set_flip_vertically_on_load`, as far as I can tell, which is useful/necessary when wanting to load image data in a format immediately consumable by OpenGL (see [Example](#Example) down below). ## Installation Add this line to your application's Gemfile: ```ruby gem 'stb_image_ffi' ``` And then execute: $ bundle Or install it yourself as: $ gem install stb_image_ffi ## Example ```ruby STBImage.stbi_set_flip_vertically_on_load 1 file = "image.jpg" width_ptr = " " * 8 height_ptr = " " * 8 channels_ptr = " " * 8 desired_channels = 3 ptr = STBImage.stbi_load(file, width_ptr, height_ptr, channels_ptr, desired_channels) width = width_ptr.unpack1 "L" height = height_ptr.unpack1 "L" channels = channels_ptr.unpack1 "L" data = ptr.get_bytes(0, width * height * channels) # ... glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGB8, width, height) glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data) ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/boatrite/stb_image_ffi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). ## Code of Conduct Everyone interacting in the STBImage project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/boatrite/stb_image_ffi/blob/master/CODE_OF_CONDUCT.md).