Jump to content

ReadPixels from Texures


Nabroski
 Share

Recommended Posts

Hello

I kind of stuck to read any data of pixels from the engine  
My goal is to read and set pixels from textures, just a little hint is probably enough.
Thank you all for your time


The playground:
http://babylonjs-playground.com/#1I5MDT#2

i think i looking for this, but i cant get it to work:


Best 
 

Edited by Nabroski
Link to comment
Share on other sites

try this i am sorry i cant get time for complete your PG :(

 

var ReadTexture = function (txt,   w, h) { 
   var gl = document.getElementById('renderCanvas')
       .getContext("webgl", { preserveDrawingBuffer: true }) || 
        eng.get().canvas.getContext("experimental-webgl", { preserveDrawingBuffer: true });
    var fb = gl.createFramebuffer();
    gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, txt, 0);
 
    var pixels = new Uint8Array(w * h * 4);
    gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, pixels); 
    return pixels;
 }

var readPixel = function (pix, x, y,w ) {
    return {
        r: pix[y * 4 * w + x * 4], 
        g: pix[y * 4 * w + x * 4 + 1],
        b: pix[y * 4 * w + x * 4 + 2], 
        a: pix[y * 4 * w + x * 4 + 3]
    };
}

usage : readPixel( ReadTexture( texture , width,height) ,x, y, width );

 

Link to comment
Share on other sites

  • 3 weeks later...

I using Dynamic Textures now, to get and set pixels, if any of you has an easy to use 
Textures RGB example i would high apprentice it. Yeah, Yeah, i learn shades, ....someday.

I experimenting with Dump Framebuffer, thank you for the tip. I apply a screenshot now real time to an object, its nice to play with

Do you want to read from a specific texture or from the rendering?  From the rendering.

http://babylonjs-playground.com/#10OY8W#2

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...