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

Cannot find a way to get the pixel data from texture or sprite. #3080

Closed
ben0bi opened this issue Oct 9, 2016 · 14 comments
Closed

Cannot find a way to get the pixel data from texture or sprite. #3080

ben0bi opened this issue Oct 9, 2016 · 14 comments
Labels
👍 Not A Bug Verified issue and is working as intended. 🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim

Comments

@ben0bi
Copy link

ben0bi commented Oct 9, 2016

Hello. I don't know if I miss something, but...

How can I get the raw pixel array of a texture? Every and every post talks about putting stuff onto a RenderTexture but there is absolutely no post about how to get the data from that texture.

I need the pixel data to output it with another protocol to a self made LED-strip-screen.

I render a RenderTexture with my whole output screen in the browser, create a sprite from it and add that to a new container, resize it to the LED-screen size and render it (scaled) to another RenderTexture....and now I am stuck by not getting this damn pixel data.

I post this as an issue because absolutely nowwhere is something about getting the data in a raw format. Only about PUTing data on the texture/sprite/container.

So, my request is: Please add a function RenderTexture.getPixelArray()/getRawData() or something like that. Or link me to the appropiate website where this is explained, I searched about 3 hours and found nothing.

[EDIT] there must be a webGL way, with NOT putting the stuff on a canvas and...so...on...don't you think?

Thanks in advance.
PIXI is great, just to say.

Regards,
ben0bi

@englercj
Copy link
Member

englercj commented Oct 9, 2016

Look at the WebGLExtract API:

https://github.com/pixijs/pixi.js/blob/master/src/extract/webgl/WebGLExtract.js

PIXI.extract.webGL.pixels(renderTexture)

@englercj englercj added 🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim Domain: API labels Oct 9, 2016
@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

Thank you very much. It would be great if this is referred in the docs, Texture-classes, with a link.

@ben0bi ben0bi closed this as completed Oct 9, 2016
@ben0bi ben0bi reopened this Oct 9, 2016
@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

I get "Uncaught TypeError: Cannot read property 'webGL' of undefined"

Is that a v4 functionality or do I have to add the class manually?
I am using v3 right now.

Regards,
Beni Yager

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Oct 9, 2016

That's how it works in V4:

renderer.extract.pixels(myContainer)

That's the code: https://github.com/pixijs/pixi.js/blob/master/src/extract/webgl/WebGLExtract.js#L126

I am not sure how did it work in V3, I'm looking at the code and just cant find it :( I remember there was something

@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

Oh I see here, I do not need a second renderTexture to render the scaled container, seems like I can just use the container itself. (...pixels(container)), very nice very nice. downloading v4, looking if it works.

[closed for now ;) ]

@ben0bi ben0bi closed this as completed Oct 9, 2016
@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Oct 9, 2016

Oh, there's something for V3:

var canvas = renderTexture.getCanvas();
var pixels = renderTexture.getPixels();

It is here: https://github.com/pixijs/pixi.js/blob/v3/src/core/textures/RenderTexture.js#L392

You need to render your stuff into renderTexture first.

@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

a little bit of nice makes the spice. :) thanks.

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Oct 9, 2016

Just remember that its a slow method. Every upload/download of texture from/to GPU is slow.

@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

Yeah but I need the bytestream to output it to the LED array. Is extract faster?

@ivanpopelyshev
Copy link
Collaborator

ivanpopelyshev commented Oct 9, 2016

No, its slow in general, in WebGL. You can do that may be one time per frame, but not more :) Also you don't have to call "renderer.render" if you only need that output. "pixels" has one inside.

@ivanpopelyshev
Copy link
Collaborator

How big is your LED?

@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

The size of the LED screen should be adjustable, that is why I scale the output with a renderTexture + Sprite combination. It is fast enough each 10 frames for now. We can right now control about 300 LED without flickering (serial data speed issues), so the screen will not be really big, only look big because of big LEDs.

Really thanks for your help. I will post some photos or a utube video when it's done and working.

@ben0bi
Copy link
Author

ben0bi commented Oct 9, 2016

Here is the first image, proofing that it may work. 400x400 scaled down to 40x40 and then put out as html text image. (once)

image

Thanks, guys.

@englercj englercj added the 👍 Not A Bug Verified issue and is working as intended. label Oct 12, 2016
@lock
Copy link

lock bot commented Feb 25, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Feb 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
👍 Not A Bug Verified issue and is working as intended. 🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim
Projects
None yet
Development

No branches or pull requests

3 participants