ruby2d / ruby2d

🎨 The Ruby 2D gem
http://ruby2d.com
MIT License
641 stars 75 forks source link

Bitmap? #57

Closed lstrzebinczyk closed 5 years ago

lstrzebinczyk commented 7 years ago

I'm thinking about writing a maze/cave generator for my game. Check this link: https://gamedevelopment.tutsplus.com/tutorials/generate-random-cave-levels-using-cellular-automata--gamedev-9664

For the generation, I would like to see a big overview of the result, like available on that link. However, if I were to construct it from squares or rectangles, it would have very poor performance.

Is there an option to have a sort of a bitmap, where I would be able to decide bitmap pixel size, which pixels are on, which off, and what the color of pixels off is? Or is there another solution for doing this efficiently?

blacktm commented 7 years ago

Great question, unfortunately nothing like this currently exists. This is quite similar to the blitting conversation we had in Gitter. One idea is to use an OpenGL texture — you can see how they are created here. We could create a generic texture concept in Simple 2D with a convenient API to draw to it, even manipulate individual pixels. Only downside is that it could potentially be a significant amount of work. Another pure Ruby idea is to create your own pixel array and figure out how to write it to a .bmp or .png file, then read it back in as an Image.

lstrzebinczyk commented 7 years ago

potentially be a significant amount of work.

Do you mean, to implement it, or to use it? I'm happy to move this issue to much, much later. I wouldn't abandon the idea completely, though.

blacktm commented 7 years ago

Well, to implement. I think it could be simple to use. In Ruby, maybe we'd create a new Texture class and expose its pixels through an array, and provide convenient methods for drawing on it (like with shapes and even other textures). You essentially could have a "painting" effect here. I'll think on this a bit, maybe prototype something in Simple 2D as a start.

blacktm commented 5 years ago

Painting pixels or creating custom textures programmatically is a really cool idea, but going to close this until we have a specific strategy or implementation in mind.