[fixed]Rendering text on a texture?

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
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

[fixed]Rendering text on a texture?

Post by no_response »

Hi all


I need to put some text on a texture at runtime.

I tried to use setRenderTarget targeting the image on a cube and a static text on it but it didn't work out so good... actually it didn't work at all.


So is there a way to do this in a somewhat normal way?
Thanks!
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

RTT seems like a good way to accomplish what you're trying to do. Can you give us more information about the problem? Maybe some code?
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

Post by no_response »

Code: Select all

IGUIStaticText* st = guienv->addStaticText(L"omgggg", rect<s32>(300, 300, 350, 350), 0, 0, 0, 0, 0);
    ITexture* rt = driver->addRenderTargetTexture(core::dimension2d<u32>(256,256), "RTT1");
    ICameraSceneNode* rttcam = smgr->addCameraSceneNode(0, vector3df(0, 200, 0));
    ISceneNode* cube = smgr->addCubeSceneNode(60);
    cube->setMaterialFlag(EMF_LIGHTING, false);
    //cube->setMaterialTexture(0, driver->getTexture("./images/fl.dat"));
    cube->setMaterialTexture(0, rt); // set material of cube to render target
    cube->setPosition(vector3df(200, 0, 0));
and in the main loop

Code: Select all

//rtt
    driver->setRenderTarget(rt, true, true, video::SColor(255,255,255,255));

    cube->setVisible(0);
    smgr->setActiveCamera(rttcam);

    smgr->drawAll();
    guienv->drawAll();
    //st->draw();

    driver->setRenderTarget(0, true, true, SColor(255,255,255,255));
    cube->setVisible(1);
    smgr->setActiveCamera(cam1);

result (glitched) :
Image

without RTT (not glitched and no second mesh cube) :
Image


What I need is embeding the text over the texture once and then using that texture, nothing dynamic is required.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

In that case don't use the RTT in the main loop. Simply create the rtt, set as render target, and render the texture (with draw2dimage) and the text with drawFont or with the gui element. After that, your rtt will have the texture and the font on top. Then just build your usual gui and scene, attach the rtt to the cube, and render it with the default render loop.
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

Post by no_response »

thanks, the texture creating is working, but...

the GUI glitch from the first screenshot still exists.
only when the cube with the created texture is on the screen however.

also, I get the warning 'Unsupported texture format'.
I have read about this warning, and yes, I tried to set ECF_A8R8G8B8 yet the warning continues to appear.

I'm using OpenGL
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You can ignore the warning or use latest SVN version, which has this fixed. Fior the rest: Don't know, maybe you want to post full code?
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

I am doing a:

Code: Select all

device->getVideoDriver()->setMaterial(device->getVideoDriver()->getMaterial2D());
after using my rtts and that pretty much fixes it. so just call it after rendering the scene.
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

Post by no_response »

full code (with all the misc functions and stuff) : [edit - navigation fixed]

Code: Select all

removed, read below
Last edited by no_response on Thu Sep 16, 2010 4:51 pm, edited 1 time in total.
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

Post by no_response »

bump.

bug also occurr with the default font.
only while the RT texture is (or partialy is) on the screen.
tried disabling orthogonal camera, didn't work.
tried several other things, yet only disabling the cube with the RT texture on it solves the problem.

I'm beggining to think that this is some kind of weird engine bug that I don't know how I caused.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

We cannot really help you if you give only such a highly specialized code. Strip down the code and remove everything that is not needed for reproduction of the bug.
no_response
Posts: 26
Joined: Fri Aug 20, 2010 11:07 am
Location: Bulgaria

Post by no_response »

here it is

Code: Select all

#include <Irrlicht.h>


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


bool keys[irr::KEY_KEY_CODES_COUNT];
class MyEventReceiver :
 public IEventReceiver {
 public:
  bool OnEvent(const SEvent &event)  {
  if(event.EventType == irr::EET_KEY_INPUT_EVENT){
                     keys[event.KeyInput.Key] = event.KeyInput.PressedDown;
                     return false;}
  return false;}};


int main(int argc, char *argv[]){
    IrrlichtDevice* device = createDevice(EDT_OPENGL, dimension2d<u32>(800, 600), 32, false, false, false, 0);
    MyEventReceiver rv;
    device->setEventReceiver(&rv);

    IVideoDriver* driver = device->getVideoDriver();
	ISceneManager* smgr = device->getSceneManager();
	IGUIEnvironment* guienv = device->getGUIEnvironment();


    smgr->addCameraSceneNode(0, vector3df(0, 200, 1), vector3df(0, 0, 1), 1, 1);



    guienv->addButton(rect<s32>(120, 30, 190, 45), 0, 201, L"asddd", L"");
    guienv->addStaticText(L"asdddddddoamgmoasmgom\nfoaomsodommogdd\nddddddddd", rect<s32>(10, 30, 100, 200), 0, 0, 0, 0, 0);


    //RTT
    ITexture* rt = driver->addRenderTargetTexture(core::dimension2d<u32>(512, 512), "rt", ECF_R8G8B8);

    driver->setRenderTarget(rt, true, true, video::SColor(255,255,255,255));
    driver->draw2DImage(driver->getTexture("./images/fl.dat"), position2d<s32>(0, 0));
    guienv->getBuiltInFont()->draw(L"OMGGG =!", rect<s32>(400, 100, 700, 300), SColor(255, 0, 0, 255), 0, 0, 0);
    driver->setRenderTarget(0);

    ISceneNode* cube = smgr->addCubeSceneNode(60);
    cube->setMaterialFlag(EMF_LIGHTING, false);
    //if this next line solves the GUI problem if commented out
    cube->setMaterialTexture(0, rt); // set material of cube to render target
    cube->setPosition(vector3df(-50, 50, 0));




    while(device->run()){
    driver->beginScene(true, true, SColor(255,255, 255, 255));
    //main window
    driver->setViewPort(rect<s32>(200, 0, 800, 600));
    smgr->drawAll();


    if(keys['A']) cube->setVisible(1);
    if(keys['D']) cube->setVisible(0);


    //guienv
    driver->setViewPort(rect<s32>(0, 0, 800, 600));
    guienv->drawAll();

    driver->endScene();
    }

    device->drop();
    device=0;
    return 0;
}
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, thanks. Bug is confirmed, but not yet identified. But I have a minimal problem with which I can work. Meanwhile, Sudi's workaround seems to be enough to fix the issue.
robcris
Posts: 1
Joined: Thu Nov 25, 2010 7:27 pm

Current status? DirectX9 seems worse...

Post by robcris »

I tried to get this code to work, have some success but it does not seem stable. Under directx9 it doesn´t work at all. Any update?
robcris
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

No, no yet.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Ok, some update. The code works if the rendering is put into a beginScene/endScene block. At least under dx9. The opengl code is still garbage, but I don't know why. The textures are all properly set. The render states look the same from the Irrlicht side. Maybe some opengl state corruption.
[update]
This issue is fixed in SVN/trunk. IIRC, due to render state changes this did not make it into the 1.7 branch.
Post Reply