Render to texture - where to start?


There are already some posts here on the topic of rendering to texture, but I thought it would make sense to ask it again given rendering in OpenFL was refactored several times in the last years.

I use official HaxeFlixel & OpenFL 8.x on native hxcpp platforms (mostly, Windows), and I already figured out how to write shaders and how to pass textures as uniforms. Now I would also like to render some HaxeFlixel sprites to texture to then use it as an input in some shader.

Any pointers on how this could be achieved on latest OpenFL?

Please note that I probably don’t want to “cacheAsBitmap” anything (not sure) because I need to update the target texture every frame. Besides, I saw some pointers to Flash APIs like Away3D, Stage3D, etc, but those are confusing for me as I never ever programmed anything Flash in days before OpenFL - are they useful at all with native platforms and HaxeFlixel?

Thank you! :smiley:

cacheAsBitmap in modern OpenFL is “render-to-texture”

sprite.filters = [ new ShaderFilter (myCustomShader) ]

The above will render the sprite to a texture, then run a custom shader as a post-process effect

1 Like

This is enlightening!

Though, will filters and cacheAsBitmap work with HaxeFlixel sprites too? (they are not same as OpenFL Sprites, but they use BitmapData for textures)

From my understanding, in HaxeFlixel there is only one big Sprite that covers the whole window, and all rendering of sprites is done by drawQuads technique nowadays (you should know better, since you implemented it!).

Anyway, I’m going to try applying the method you suggest to the whole window’s Sprite. It would be more flexible to have some textures of less size than the window size, but it’s a lot better than nothing, if works. :slight_smile:

EDIT: it worked, going to dig further…

Turned out that in HaxeFlixel every FlxCamera draws on a Sprite, so one can at least do stuff like:

override public function update(elapsed:Float):Void
	if ( != null)
                someShader.mainTexture.input =;