Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define Pixmap and PixmapAtlas to abstract image loading/mgmt #244

Merged
merged 11 commits into from May 23, 2022

Conversation

nogginly
Copy link
Contributor

@nogginly nogginly commented May 14, 2022

TL; DR
@blacktm, I'd like to propose abstracting image loading (and mgmt) from the renderable Image with the eventual goal of being able to support drawing images (and, later, text) into a Canvas. I'm use the name Pixmap to avoid breaking the current APIs, but as always I'm open to better naming.

Usage

  1. Setup a PixmapAtlas once and use it when creating image-like shapes (i.e. Image, Sprite, Tileset) to ensure that an image file is loaded only once. For example:
  ...
  atlas = PixmapAtlas.new
  Sprite.new 'assets/hero.png', atlas: atlas
  ...
  1. Canvas can draw Pixmaps, which can be created directly, or even better, can be created using a PixmapAtlas to ensure the same image doesn't get loaded more than once. For example:
  ...
  atlas = PixmapAtlas.new
  hero = atlas.load_and_keep_image('assets/hero.png') as :hero
  canvas.draw_pixmap atlas[:hero], x: 10, y: 100 
  ...  

Changes/commits

  • New
    • Define a Pixmap which can be used to load an image file and convert to Texture when needed
      • ✅ Add tests
    • Define a PixmapAtlas which can be used to manage loading/caching Pixmap by name.
      • ✅ Add tests
    • Add Canvas#draw_pixmap method to draw a Pixmap with resizing
      • ✅ Support drawing cropped pixmap into Canvas so portions of a pixmap can be drawn. (See coin in screenshot below)
  • Changes
    • Image supports a load_image_as_texture class method which, given a file path and optional PixmapAtlas, will use Pixmap to load the image and track it in the atlas by file path.
      • ✅ Expand test specs to verify atlas
    • Sprite and Tileset modified to use above Image loader method and support optional atlas in constructor
    • Converting image to GL texture modified to support GL_BGR for non-OpenGL ES, leaving in the pixel manipulation otherwise.
  • Removals
    • Removed the native Image.ext_load_image class method
      • Native image loading is done by Pixmap.ext_load_pixmap

Screen Shot 2022-05-23 at 02 30 38

I realise this is a "design" change, so I am completely open to changes that better align with the goals of Ruby2D.

@nogginly nogginly changed the title Draft: Define pixmap and atlas to abstract image loading/mgmt Define Pixmap and PixmapAtlas to abstract image loading/mgmt May 23, 2022
@blacktm blacktm merged commit e321954 into ruby2d:main May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants