[fixed] Render to Texture causes upside-down text

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

[fixed] Render to Texture causes upside-down text

Post by squisher »

This displays a black screen with upside-down text:

Code: Select all

#include <irrlicht.h>

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

using namespace irr;
using namespace scene;
using namespace video;
using namespace gui;
using namespace core;


/*** main function **************************************************************/

int main(int argc, char* argv[])
{
   u32 height = 300;
   u32 width = 400;
   IrrlichtDevice* device = createDevice(video::EDT_OPENGL, dimension2d<s32>(width, height), 32,
       false, false, true);
 
   IVideoDriver* driver = device->getVideoDriver();
   ISceneManager* smgr = device->getSceneManager();

   smgr->addCameraSceneNode();
   
   ISceneNode* renderNode = smgr->addCubeSceneNode(40, 0, -1, vector3df(12,-12,68), vector3df(0, 0, 0));
   
   ITexture* renderTexture = driver->createRenderTargetTexture(dimension2d<s32>(256, 256));
   renderNode->getMaterial(0).setTexture(0, renderTexture);
   
   IGUIStaticText* text = 0;
   IGUIEnvironment* guienv = device->getGUIEnvironment();
   guienv->getSkin()->setColor(EGDC_BUTTON_TEXT, SColor(255,255,255,255));
   text = guienv->addStaticText(L"Here we go!",
       rect<s32>(32, height - 32 - 16, width - 32, height - 16), false, false);
   
   u8 debugTimer=0;
   
   while(device->run())
   {
       if (++debugTimer > 15)
       {
           debugTimer = 0;
           stringw str = "UPSIDE DOWN TEXT?: ";
           str += rand() % 52308823;
           str += "  TIME: ";
           str += device->getTimer()->getRealTime();
           str += "  ____UNDERLINES_____";
           text->setText(str.c_str());
       }
       
       driver->beginScene(true, true, 0);
       smgr->drawAll();
       guienv->drawAll();
       driver->endScene();
   }
} 
Coment out the following two lines:

Code: Select all

   //ITexture* renderTexture = driver->createRenderTargetTexture(dimension2d<s32>(256, 256));
   //renderNode->getMaterial(0).setTexture(0, renderTexture);
And the text is right-side up again. Help!
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

Works just fine for me with the EDT_DIRECT3D9 driver...
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

This is probably due to the RTT fix for OpenGL, which is not properly reset. I'll look into this.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

I can confirm this bug on the svn,i fixed it for a little while then came back to standard irrlicht,

I think the drawImage2D was written intending to flip its texture coords if its trying to draw a rtt, howver its flipping on the basis if the previous material had an rtt texture on texture unit 0;

Code: Select all

const bool isRTT = Material.getTexture(0) && Material.getTexture(0)->isRenderTarget();
	const core::dimension2d<s32>& ss = texture->getOriginalSize();
	const f32 invW = 1.f / static_cast<f32>(ss.Width);
	const f32 invH = 1.f / static_cast<f32>(ss.Height);
	const core::rect<f32> tcoords(
			sourcePos.X * invW,
			(isRTT?(sourcePos.Y + sourceSize.Height):sourcePos.Y) * invH,
			(sourcePos.X + sourceSize.Width) * invW,
			(isRTT?sourcePos.Y:(sourcePos.Y + sourceSize.Height)) * invH);
from
void COpenGLDriver::draw2DImage(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::rect<s32>& sourceRect,
const core::rect<s32>* clipRect, SColor color,
bool useAlphaChannelOfTexture)

i think that bool should be checking if "texture" is an rtt rather than the material's texture since the method is drawing the texture passed to it rathter than any material.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Post by squisher »

Yep! I changed line 1230 to

Code: Select all

const bool isRTT = texture && texture->isRenderTarget();
and recompiled Irrlicht, and now it works. Thanks!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yep, correct. Fixed in revision 1578.
merovingian
Posts: 37
Joined: Thu Feb 28, 2008 4:34 am
Location: Perth, Western Australia

Post by merovingian »

Thanks a lot for fixing this. My flipped RTTs (as we discussed previously on a different thread) are now fixed.

As a small aside, this fix is not in the 1.4.2 binaries (for Win32-gcc at least). But if I checkout 1580 from the trunk, and build my own DLL, the problem is fixed.
Post Reply