Render targets in emscripten

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Render targets in emscripten

Post by n00bc0de »

I am trying to render to a texture in the emscripten port and I always get a black screen. It works find if just using the default render target.

Are render targets just not supported through emscripten?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Render targets in emscripten

Post by CuteAlien »

Sorry didn't try RTT's back then and it's been a few years since I experimented with emscripten. I just run a quick test and it seems emscripten will need either power of two textures (so like 128, 256, 512 etc) or CLAMP_TO_EDGE has to be set when drawing textures. As a workaround - either use a power of two render target texture or set the following lines before drawing your RTT:

Code: Select all

SMaterial& matRtt = driver->getMaterial2D();
matRtt.TextureLayer[0].TextureWrapU = ETC_CLAMP_TO_EDGE;
matRtt.TextureLayer[0].TextureWrapV = ETC_CLAMP_TO_EDGE;
driver->enableMaterial2D(true);
It's probably a good idea to just make this the default for InitMaterial2D in the WebGL driver, but as usual I checked the forum before going to sleep, so not digging deeper anymore today ;-)

Also warning - emscripten was pretty experimental. Also by now some of it is a bit outdated (haven't touched that in 3-4 years). Some stuff will not work yet ,for example particles. If you have other bugs always a good idea to check the console output in the browser (F12 in Firefox).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
n00bc0de
Posts: 55
Joined: Tue Oct 04, 2022 1:21 am

Re: Render targets in emscripten

Post by n00bc0de »

Thanks. That instantly fixed my issue.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Render targets in emscripten

Post by CuteAlien »

If you update to svn ogl-es [r6674] you can now remove those lines again if you did draw the RTT with drawTexture functions.
I had hoped I could make clamp to edge default for 2D, but turns out that can break stuff, so now WebGL driver doing checks.
Interestingly enough we already convert all other textures to power of two. Which may not really be necessary in all cases I suppose, but I won't touch that for now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply