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

Does this work with WebGLRenderingContext? #1

Closed
jonobr1 opened this issue May 4, 2011 · 6 comments
Closed

Does this work with WebGLRenderingContext? #1

jonobr1 opened this issue May 4, 2011 · 6 comments

Comments

@jonobr1
Copy link

jonobr1 commented May 4, 2011

No description provided.

@antimatter15
Copy link
Owner

No idea

@jonobr1
Copy link
Author

jonobr1 commented May 4, 2011

totally does. SO AWESOME!

sudo code:

var readBuffer = new Uint8Array(canvas.width * canvas.height * 4);
context.readPixels(0, 0, canvas.width, canvas.height, context.RGBA, context.UNSIGNED_BYTE, readBuffer);
encoder.addFrame(readBuffer, true);

I noticed the AS3 version is under MIT License. Is yours as well?

@antimatter15
Copy link
Owner

Yeah

@deethee
Copy link

deethee commented Apr 9, 2013

for some reason, on webgl renderer method getcontext is always null.

The only method returning an image is canvas.toDataURL("image/png"); this seems not to be compatible with this function, or maybe anyone has an idea how?

@ranbuch
Copy link

ranbuch commented Apr 18, 2016

Hi @deethee,
This link should help you:
http://stackoverflow.com/questions/32556939/saving-canvas-to-image-via-canvas-todataurl-results-in-black-rectangle#answers

Also to get the context you can always hijack createElement and getContext methods and save the context:

        new function() {
                var orgCreateElement = document.createElement;
                // hijack createElement to hijack all the canvases getContext  
                Object.defineProperty(document, 'createElement', 
                {value: function(type) {
                    var ans = orgCreateElement.apply(this, Array.prototype.slice.call(arguments));
                    if (type == 'canvas') {
                        var orgGetContext = ans.getContext;
                        // hijack getContext to catch all the contexts and save then in window.mainContext (or wherever . . .) 
                        ans.getContext = function() {
                            if (!window.mainContext)
                                window.mainContext = [];
                            if (typeof arguments[1] === 'object')
                                // set preserveDrawingBuffer = true will help you with canvas.toDataURL("image/png"); method
                                arguments[1].preserveDrawingBuffer = true;
                            var c = orgGetContext.apply(this, Array.prototype.slice.call(arguments));
                            window.mainContext.push(c); 
                            return c;
                        };
                    }
                    return ans;
                }});
        }

That may be an overkill but just in case you're using some other framework (such as three.js) . . .
Make sure this code is running before any canvas has been created.
Your context is inside window.mainContext array.

Regarding @jonobr1 code unfortunately the browser always gets stuck in this line:

encoder.addFrame(readBuffer, true);

with very high CPU hz

@ranbuch
Copy link

ranbuch commented Apr 18, 2016

I've decided to go with that one:
https://github.com/yahoo/gifshot
while providing an images array with canvas.toDataURL("image/png") as images sources.

Works for me.

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