Alfredo Posted July 15, 2014 Share Posted July 15, 2014 Hi guys,how can I draw on a texture pixel by pixel? I cannot find it in the documentation. Quote Link to comment Share on other sites More sharing options...
xerver Posted July 15, 2014 Share Posted July 15, 2014 Draw to a canvas, and use the canvas as the texture. Quote Link to comment Share on other sites More sharing options...
mrBRC Posted July 17, 2014 Share Posted July 17, 2014 @Xerver, What do you mean exactly?how do you use a separate canvasContext as a PIXI.Texture or PIXI.BaseTexture? Quote Link to comment Share on other sites More sharing options...
mrBRC Posted July 17, 2014 Share Posted July 17, 2014 (edited) nevermind.. I found a method to do this.. however, it is not immediately obvious how you can bind and update the texture when the canvas changes.. at any rate.. the following code sample demonstrates how to use a separate canvas as a PIXI.BaseTexture// I created a canvas element with the id "drawpanel" on my page.// My renderer is WebGL, function LoadCanvasImage() { var c = document.getElementById("drawpanel"); pixiCanvasRenderer = new PIXI.CanvasRenderer(c.width,c.height,c,true); var grd=pixiCanvasRenderer.context.createRadialGradient(75,50,5,90,60,100); grd.addColorStop(0,"red"); grd.addColorStop(1,"white"); // Fill with gradient pixiCanvasRenderer.context.fillStyle=grd; pixiCanvasRenderer.context.fillRect(10,10,150,100); var source = new Image(); source.src = pixiCanvasRenderer.view.toDataURL(); // in this instance, 'Canvas'.toDataURL returns "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAACWCAYAAABkW7XSAAAYE0lEQ…TWsFPLE2MExosAgTXenPKMGIFhI0BgDTu1PDFGYLwI/A9PJKWFOlTAfAAAAABJRU5ErkJggg==" // reference http://www.html5canvastutorials.com/advanced/html5-canvas-save-drawing-as-an-image/ var BaseTexture = new PIXI.BaseTexture(source, PIXI.scaleModes.LINEAR); var Texture = new PIXI.Texture(BaseTexture); var mySprite = new PIXI.Sprite(Texture); stage.addChild(mySprite);}I'm not showing the Stage initialization here, or the animation loop.. but that should be easy enough to reference and implement in the pixi examples on github. EDIT: Added toDataURL instance data, and an article reference on it. Edited July 17, 2014 by mrBRC Quote Link to comment Share on other sites More sharing options...
Alfredo Posted July 17, 2014 Author Share Posted July 17, 2014 Thanks, solved. Quote Link to comment Share on other sites More sharing options...
Mat Groves Posted July 17, 2014 Share Posted July 17, 2014 Hey guys easiest way is to use:// create a regular canvasvar canvas = document.create('canvas')// make your canvas awesome...// then use it as a texture:var canvasTexture = PIXI.Texture.fromCanvas(canvas);var sprite = new PIXI.Sprite(canvasTexture) Alfredo and mrBRC 2 Quote Link to comment Share on other sites More sharing options...
Alfredo Posted July 17, 2014 Author Share Posted July 17, 2014 Hey guys easiest way is to use:// create a regular canvasvar canvas = document.create('canvas')// make your canvas awesome...// then use it as a texture:var canvasTexture = PIXI.Texture.fromCanvas(canvas);var sprite = new PIXI.Sprite(canvasTexture)Thanks, much cleaner, I have one other question, why doing setTexture works using canvas, and it doesn't using WebGL? 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.