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

Alpha is always opaque #26

Closed
JoshCheek opened this issue Nov 29, 2016 · 9 comments
Closed

Alpha is always opaque #26

JoshCheek opened this issue Nov 29, 2016 · 9 comments
Assignees

Comments

@JoshCheek
Copy link

Per suggestion I'm moving this comment to a new issue :P Note that this diff was applied locally.

  R = ((dc & Rmask) + (( (color & Rmask) - (dc & Rmask) ) * alpha >> 8)) & Rmask;
  G = ((dc & Gmask) + (( (color & Gmask) - (dc & Gmask) ) * alpha >> 8)) & Gmask;
- B = ((dc & Bmask) + (( (color & Bmask) - (dc & Bmask) ) * alpha >> 8)) & Bmask;
+ // need to do different shifting here to avoid overflow
+ B = ((dc & Bmask) + ((((color & Bmask) - (dc & Bmask)) >> 8) * alpha)) & Bmask;

Alpha is still not responding (it's always fully opaque). Note that it's not responding on rect or point, eitiher. Alpha also doesn't work on 24 bpp, though there is code in there to support it. Alpha is handled differently from all the other channels, it gets passed in as its own arg. I assume it works in general, because I assume anti aliasing uses it, but I couldn't think of an example that would make it obvious. The one below shows that it is always opaque.

screenshot 2016-11-29 16 50 41

require "graphics"

side    = 100
alphas  = [0, 0.5, 1, 128, 255]
drawing = Graphics::Drawing.new alphas.length*1.5*side+side/2, side*2, 32
drawing.color.default_proc = -> h, k { k }

alphas.each_with_index do |alpha, i|
  color = drawing.screen.format.map_rgba(255, 255, 255, alpha)
  drawing.rect i*1.5*side+side/2, side/2, side, side, color, true
  drawing.text alpha.to_s, i*1.5*side+side/2, 1.5*side, :white
end

drawing.run
@zenspider
Copy link
Owner

from https://www.libsdl.org/release/SDL-1.2.15/docs/html/sdlfillrect.html

The color should be a pixel of the format used by the surface, and can be generated by the SDL_MapRGB or SDL_MapRGBA functions. If the color value contains an alpha value then the destination is simply "filled" with that alpha information, no blending takes place.

But I'm also using SGE, so I'll poke in there as well.

This would definitely be one area where upgrading to SDL 2 would be worth it in the long run... But DAMN is it poorly documented and shitty.

@zenspider zenspider self-assigned this Nov 30, 2016
@zenspider
Copy link
Owner

It also appears that map_rgba is dropping the alpha values entirely. I'm poking to see if I'm initializing something incorrectly.

@zenspider
Copy link
Owner

PAINFULLY reworking some of this stuff... I've got some wierd blending going on. Dunno why alpha blend 0 of red on white results in yellow, but alpha blend 1 doesn't:

screen shot 2016-11-29 at 20 32 27

@zenspider
Copy link
Owner

OK... my blue fix is the problem.

screen shot 2016-11-29 at 20 37 26

@zenspider
Copy link
Owner

require "graphics"

class Bug026 < Graphics::Simulation
  def initialize
    super 400, 300, 32


    register_color :b0, 255, 0, 0, 0
    register_color :b1, 255, 0, 0, 1
    register_color :b2, 255, 0, 0, 128
    register_color :b3, 255, 0, 0, 255
  end

  def draw iteration
    clear

    rect 50, 100, 300, 50, :white, :filled

    rect 75, 50, 50, 150,  :b0, :filled
    rect 150, 50, 50, 150, :b1, :filled
    rect 225, 50, 50, 150, :b2, :filled
    rect 300, 50, 50, 150, :b3, :filled

    # self.done = true
  end
end

Bug026.new.run if $0 == __FILE__

@zenspider
Copy link
Owner

this is fixed for your immediate problem, but requires reworking basically all of the drawing primitives.

@zenspider
Copy link
Owner

This is handled, yes?

@JoshCheek
Copy link
Author

It's fixed on Github, but not in the released gem.

@zenspider
Copy link
Owner

Kk. I'm gonna close this. I'm not too far from a release? I don't think? I dunno. I'm mentarbating a bit on some of the color stuffs.

Repository owner locked and limited conversation to collaborators Jan 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants