Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Blending bitmaps

Is it possible to use blending modes (Add and Subtract, the options for sprites) when combining bitmaps in a window?

I made a method using get_pixel and set_pixel, like this ...

    # Adds bitmap to otherbitmap and displays in a window
    bitmap = RPG::Cache.fog('006-Sandstorm02', 0)
    otherbitmap = RPG::Cache.fog('007-Water01', 0)
      windowfun = Window_Base.new(0, 0, 300, 300)
      windowfun.contents = Bitmap.new(bitmap.width, bitmap.height)
      for x in 0...bitmap.width
        for y in 0...bitmap.height
          color1 = bitmap.get_pixel(x, y)
          color2 = otherbitmap.get_pixel(x, y)
          newcolor = Color.new(color1.red + color2.red, color1.green +
                color2.green, color1.blue + color2.blue)
          windowfun.contents.set_pixel(x, y, newcolor)
        end
      end

... but it's horribly time-consuming.  Is there a better way?
 
That's probably the best you are going to be able to do. Might I take this, turn it into a method and add it to the MACL?

Code:
class Bitmap
  def add_bitmap_blend(x, y, bitmap, src_rect = bitmap.rect)
    for i in 0...src_rect.width
      for j in 0...src_rect.height
        c1 = get_pixel(x + i, y + j)
        c2 = bitmap.get_pixel(src_rect.x + i, src_rect.y + j)
        nc = Color.new(c1.red + c2.red, c1.green + c2.green, c1.blue + c2.blue)
        set_pixel(x + i, y + j, nc)
      end
    end
  end
end

Now, I doubt this will be any quicker, just more organized, you can have this as your code, after you add the above method into your scripts somewhere.

Code:
  bitmap = RPG::Cache.fog('006-Sandstorm02', 0)
  bitmap.add_bitmap_blend(0, 0, RPG::Cache.fog('007-Water01', 0))
  window = Window_Base.new(0, 0, 300, 300)
  window.contents = bitmap
 
Sure!  The slow processing time makes it less useful, though.  Certainly not something you can update every frame.

And I guess you know you can mimic the subtraction blending mode with
Code:
nc = Color.new(c1.red - c2.red, c1.green - c2.green, c1.blue - c2.blue)
as line 7.

This came about because I was actually trying to haxx0r your own screenshot module so it supported blending modes.  :P  It's funny that there's no way to access the blending modes for bitmaps, considering they work so fast and well for sprites.
 
So, how would you gather the "raw" bitmap data (i mean, even a pointer to a buffer containing the pixel vales) and send it to the host dll? With loops going through 0...sizes and putting it into the array? The loops would be all the same as in those previous examples. Even with that, calling a DLL has its overhead anyway.

The solution is called SDL. ^^
 
Not exactly... RubySDL is so low-level for a higher language like ruby. RUDL is just more object-oriented and better designedl. RubySDL is just a plain extension of SDL in Ruby. Also, it requires a REAL Ruby interpreter running. I was referring to this one. The best thing to do is to make a DLL of your own using SDL and blatantly copy all ideas from RGSS to it. Then you´ll have a cross-platform better-than-rgss library that you can use to develop your games, and people without windows will still play it with native OS support. Embedding Ruby after that is a bit difficult, but possible. For better performance and easier implementation, it´s recommended to write all code in C, as Ruby is built up on C.

But this is way too much ahead of what the thread starter wanted lol
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top