[fixed]Rendering text on a texture?
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
[fixed]Rendering text on a texture?
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!
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!
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
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));
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) :
without RTT (not glitched and no second mesh cube) :
What I need is embeding the text over the texture once and then using that texture, nothing dynamic is required.
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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.
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
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
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
I am doing a:
after using my rtts and that pretty much fixes it. so just call it after rendering the scene.
Code: Select all
device->getVideoDriver()->setMaterial(device->getVideoDriver()->getMaterial2D());
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.
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
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.
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
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.
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.
-
- Posts: 26
- Joined: Fri Aug 20, 2010 11:07 am
- Location: Bulgaria
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;
}
Current status? DirectX9 seems worse...
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
-
- Admin
- Posts: 14143
- Joined: Wed Apr 19, 2006 9:20 pm
- Location: Oldenburg(Oldb), Germany
- Contact:
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.
[update]
This issue is fixed in SVN/trunk. IIRC, due to render state changes this did not make it into the 1.7 branch.