Raveline Posted February 23, 2014 Share Posted February 23, 2014 Hello, I'm trying to get used to Pixi. I'm pretty impressed by the library ! However, I'm having a hard time knowing the extent of everything it has to offer.I'm trying to store a map in a single picture (with a tilemap system behind it ; each pixel stores a tile number through its color). But to use this, I would need to be able to read an image pixel by pixel, so that I can get the pixel colors and build my map through that. I've been browsing the documentation, but couldn't find any function doing that. So is there any way to get per-pixel details from a loaded texture ? Thank you in advance for your help ! Quote Link to comment Share on other sites More sharing options...
xerver Posted February 23, 2014 Share Posted February 23, 2014 You can do this with the raw canvas API: http://stackoverflow.com/questions/667045/getpixel-from-html-canvas Or obviously in a webgl shader if you only need it for drawing purposes. Quote Link to comment Share on other sites More sharing options...
Raveline Posted February 23, 2014 Author Share Posted February 23, 2014 Yes, I know the canvas can get me access to the displayed pixels, but this is not what I'm trying to do. I just want to load an image in memory, get its pixel, and be done with it - the image in itself is just a map, like a config file if you want. So I don't want to display it. I found an idea in Stack Overflow, though, which would give me the following implementation : function MapLoader(source, context) { var texture = context.createTexture(); texture.image = new Image(); texture.image.onload = function() { var framebuffer = context.createFramebuffer(); context.bindFramebuffer(context.FRAMEBUFFER, framebuffer); context.framebufferTexture2D(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.TEXTURE_2D, texture, 0); var data = new Uint8Array(texture.image.width * texture.image.height * 4); context.readPixels(0,0,texture.image.width,texture.image.height,context.RGBA, context.UNSIGNED_BYTE, data); context.deleteFramebuffer(framebuffer); }; texture.image.src = source;}But oddly enough, this gives me the following error (on Chrome) :[.WebGLRenderingContext]GL ERROR :GL_INVALID_OPERATION : glFramebufferTexture2D: Firefox also throws an error ("Incomplete framebuffer"). I get my context directly from the renderer object of Pixie (its gl property). So, I'm still stuck... I guess I can do without the map stored in an image, but I find it much more practical than dealing with a JSON. Quote Link to comment Share on other sites More sharing options...
xerver Posted February 23, 2014 Share Posted February 23, 2014 You don't have to display a canvas, you can create one and never add it to the DOM. Quote Link to comment Share on other sites More sharing options...
Raveline Posted February 23, 2014 Author Share Posted February 23, 2014 Damn ! Should have thought about that ! Thank you so very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.