evanw / glfx.js

An image effects library for JavaScript using WebGL
https://evanw.github.io/glfx.js/
MIT License
3.26k stars 402 forks source link

Using kind of globalAlpha with glfx #32

Closed DeathAngelDaemon closed 8 years ago

DeathAngelDaemon commented 8 years ago

Hello,

I use glfx to switch between different images on the created canvas. That's working so far. But I also want to have a smooth fading effect when the images are switching.

For canvas there is a method called globalAlpha which can be assigned to a 2d context of a canvas. Sadly glfx creates a canvas with a webgl context and I cannot assign a second context to that canvas. So how can I use globalAlpha on my glfx canvas? Or is there another simple method (for switching with fade) which can be used in combination with glfx?

Any suggestions are appreciated. Thx :)

evanw commented 8 years ago

The globalAlpha attribute is part of the 2D canvas spec, not the WebGL canvas spec, so that won't work. It's confusing because they both use the <canvas> element but the 2D canvas API is entirely separate from the WebGL canvas API. One easy way of transitioning between any two DOM elements is to make two of them, position them on top of each other, and animate the opacity of the one in front to do the fade. It's definitely possible to implement a fade with WebGL inside a single <canvas> but this library doesn't include support for that unfortunately.

DeathAngelDaemon commented 8 years ago

Sorry, for my late response. Thx for your hint, that's exactly what I will do now. I just had the hope their is another possibility. So, thx for the plugin und your explanation.