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

Transparent pixels overwrite existing pixels on mlx_put_image_to_window #36

Open
MrCrackerplays opened this issue Aug 11, 2021 · 3 comments

Comments

@MrCrackerplays
Copy link

When trying to use an .xpm image with transparency that transparency will replace pixels despite being completely transparent. Using the mac mlx transparency works fine:
bug difference
Mac left, Linux right, using the same test code where first blue.xpm is put to the window and then red.xpm is put to the window. (both 8x8 pixels, hence the weirdly thin top bars of the windows)

@paulo-santana
Copy link

In the test program, the blowfish sprite is drawn with its transparent pixels as if they were opaque.

mlx

@Rakjlou
Copy link

Rakjlou commented Jan 28, 2022

Same problem here. Hope it's fixed someday.

@Rush-iam
Copy link

Hello!
Faced same issue while trying to port my cub3D from MacOS to Linux/Windows.
I dived into X11 manuals and found the way to add alpha channel to MLX - by using XRender extension which can blend images.
You can find modified MinilibX Linux on my project page:
https://github.com/Rush-iam/nGragasstein3D-cub3D
May be you need to install required libraries before:
apt install libxrender-dev

To use: function mlx_new_image_alpha() with same arguments as mlx_new_image() - it will create image, which will be blended on top of other images. From my tests there is almost no performance penalty.
I checked work only on WSL2 without SHM, so don't know how it behaves on true Linux environment - will be glad if you'll post any bugs.

Alpha channel in X11 works not the same way as in stock MLX.
255 is fully opaque and 0 is full transparent here (inverted to MLX).
So you need to draw accordingly - set upper bits of color to 0xFF if you want them to be opaque.
(if anybody knows how to invert it on X11 side - I will be grateful)
There is also another issue - if you want to play with semi-transparency - you should premultiply your color relative to alpha value before outputting - X11Render don't do that.

Here is screenshot from my cub3D with semi-transparent weapon glow - just made it to work after few days and now happy))
image

p.s. I also modified MLX by implementing some kind of double buffer - it now writes image to main buffer only once a frame.
In stock MLX it writes every time you call put_image_to_windows, so it can result in flickering images if there are lot of put_image's per frame.

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

No branches or pull requests

4 participants