Resolution limits of the screenshots.

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Resolution limits of the screenshots.

Post by lvgeng »

Recently, I tried to save the rendering results by the function createScreenShot and writeImageToFile.
It works fine in most situation, but as long as the rendering zone has a larger height than 1012 pixels, the top part will be left totally black with nothing.
I think it might be some kind of memory limits problem?
My code related is here.

Code: Select all

videoDriver->writeImageToFile(videoDriver->createScreenShot(), path(filename.c_str()));
PS: is that possible for us to render something with a really high resolution but display at a lower resolution? For instance, if I want to render something 1920X1080, do I have to have a window with the same (or lager) resolution?
Foaly
Posts: 142
Joined: Tue Apr 15, 2014 8:45 am
Location: Germany

Re: Resolution limits of the screenshots.

Post by Foaly »

Make sure to Drop() the image after saving it.

And the screenshot resolution is your rendering resolution.
If you need a higher resolution, you can use render targets. There's a tutorial on that: http://irrlicht.sourceforge.net/docu/example013.html
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

Foaly wrote:Make sure to Drop() the image after saving it.

And the screenshot resolution is your rendering resolution.
If you need a higher resolution, you can use render targets. There's a tutorial on that: http://irrlicht.sourceforge.net/docu/example013.html
Em... I tried to use the following code.

Code: Select all

 
IImage* screenshot = videoDriver->createScreenShot();
videoDriver->writeImageToFile(screenshot, path(filename.c_str()));
 
But the problem is that there is no Drop() method for IImage, I guess?
I did try render to target before, but it appears that you cannot set a render target larger than the graphic device, because they share the same buffer. Personally I think the graphic device is exactly the size of the window? Or is it possible to set the window size and the graphic device size seperately?
diho
Posts: 46
Joined: Fri May 20, 2011 9:01 pm
Location: Netherlands

Re: Resolution limits of the screenshots.

Post by diho »

Take a look at this: http://irrlicht3d.org/wiki/index.php?n=Main.TakingAScreenShot

According to this, you should be able to call drop(). Sorry I am not able to try it myself atm.

-Diho
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Resolution limits of the screenshots.

Post by hendu »

Code: Select all

 
void savetex(ITexture *tex) {
 
        IImage *tmp = g->irrdrv->createImage(tex, position2di(0,0), tex->getSize());
        stringc name = tex->getName().getPath();
        name += ".png";
        g->irrdrv->writeImageToFile(tmp, name.c_str());
        tmp->drop();
}
 
Render to a RTT and save like this. I've used it for 8192x8192 images.
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

hendu wrote:

Code: Select all

 
void savetex(ITexture *tex) {
 
        IImage *tmp = g->irrdrv->createImage(tex, position2di(0,0), tex->getSize());
        stringc name = tex->getName().getPath();
        name += ".png";
        g->irrdrv->writeImageToFile(tmp, name.c_str());
        tmp->drop();
}
 
Render to a RTT and save like this. I've used it for 8192x8192 images.
Problem. I assumed that the irrdriv is the IVideoDriver* videoDriver = device->getVideoDriver();
And made some change to the function.

Code: Select all

void savetex(ITexture *tex, std::string filename, IVideoDriver* videoDriver) {
 
        IImage *tmp = videoDriver->createImage(tex, position2di(0,0), tex->getSize());
        //stringc name = tex->getName().getPath();
        //name += ".png";
        videoDriver->writeImageToFile(tmp, filename.c_str());
        tmp->drop();
}
How I used the rendertarget:

Code: Select all

  video::IRenderTarget* simulatorRenderTarget = 0;
  video::ITexture* renderTargetTex = 0;
  scene::ICameraSceneNode* fixedCam = 0;
  renderTargetTex = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "RTT1", video::ECF_A8R8G8B8);
  video::ITexture* renderTargetDepth = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "DepthStencil", video::ECF_D24S8);
  simulatorRenderTarget = videoDriver->addRenderTarget();
  simulatorRenderTarget->setTexture(renderTargetTex, renderTargetDepth);
  videoDriver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, backgroundColor);
 
  videoDriver->setRenderTargetEx(simulatorRenderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0));
How I called the function:

Code: Select all

filename = "Img-testing-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
savetex(renderTargetTex, filename, videoDriver);
 
But problem is, I have some errors:

Code: Select all

Irrlicht Engine version 1.9.0
Linux 3.19.0-49-generic #55~14.04.1-Ubuntu SMP Fri Jan 22 11:24:31 UTC 2016 x86_64
Creating X window...
GLX >= 1.3
Visual chosen: : 33
Using renderer: OpenGL 4.5.0
GeForce GTX TITAN/PCIe/SSE2: NVIDIA Corporation
OpenGL driver version is 1.2 or better.
Dedicated video memory (kB): 6291456
Total video memory (kB): 6291456
Available video memory (kB): 5510780
GLSL version: 4.5
[1]    10344 segmentation fault (core dumped)  ./pattern-irrlicht t 1000
 
Any ideas?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Resolution limits of the screenshots.

Post by CuteAlien »

What's the callstack?
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
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

CuteAlien wrote:What's the callstack?
Sorry I am a little bit confused. What did you mean...?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Resolution limits of the screenshots.

Post by CuteAlien »

When you have a crash like a segmentation fault then you can get a callstack telling you where it crashed. Just use any debugger for that (most IDE's have one included and will show it automatically unless you have the callstack-window hidden). That way you know the exact line where it crashed and from where it was called. Without that info it's very hard to figure out crashes.

If your IDE has no debugger then use gdb (when your app is called pattern-irrlicht then start with "gdb ./pattern-irrlicht", in dbg type "run" then after the crash type "bt" to get the callstack).

edit: You have to compile your project with debug information enabled ('-g') to get debuggers working.

edit2: Also - please don't cross-post the same problem into several threads. That makes the discussion really complicated as half the people then answer in one thread and half in the other.

edit3: When you are not familiar with debuggers at all, please invest some time into learning one. It's very simple (just 4-5 commands to learn, inside IDE's you even just have to press some buttons) and programming will get so much easier for you after you learned that! It's one of the most useful tools to know as programmer and even experienced programmers will spend a lot of time in the debugger. You will probably have learned to use it in an hour.
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
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

CuteAlien wrote:When you have a crash like a segmentation fault then you can get a callstack telling you where it crashed. Just use any debugger for that (most IDE's have one included and will show it automatically unless you have the callstack-window hidden). That way you know the exact line where it crashed and from where it was called. Without that info it's very hard to figure out crashes.

If your IDE has no debugger then use gdb (when your app is called then start with "gdb ./pattern-irrlicht", in dbg type "run" then after the crash type "bt" to get the callstack).

edit: You have to compile your project with debug information enabled( aka '-g') to get debuggers working.

edit2: Also - please don't cross-post the same problem into several threads. That makes the discussion really complicated as half the people then answer in one thread and half in the other.

edit3: When you are not familiar with debuggers at all, please invest some time into learning one. It's very simple (just 4-5 commands to learn, inside IDE's you even just have to press some buttons) and programming will get so much easier for you after you learned that! It's one of the most useful tools to know as programmer and even experienced programmers will spend a lot of time in the debugger. You will probably have learned to use it in an hour.
Ha~ Now I know what you meant! Here is my function.

Code: Select all

void savetex(ITexture *texture, std::string filename, IVideoDriver* videoDriver) {
 
    // void* imageData = texture->lock(true);
    video::IImage* image = videoDriver->createImageFromData (
        texture->getColorFormat(),
        texture->getSize(),
        texture->lock( irr::video::E_TEXTURE_LOCK_MODE::ETLM_READ_WRITE),
        false  //copy mem
    );
 
    videoDriver->writeImageToFile(image, path(filename.c_str()));
    texture->unlock();
}
And here is what I got...

Code: Select all

 
Program received signal SIGSEGV, Segmentation fault.
__memcpy_sse2_unaligned ()
    at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:33
33  ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S: No such file or directory.
(gdb) bt
#0  __memcpy_sse2_unaligned ()
    at ../sysdeps/x86_64/multiarch/memcpy-sse2-unaligned.S:33
#1  0x00000000004f2933 in irr::video::CImage::CImage (this=0xd4cfa0, 
    format=irr::video::ECF_A8R8G8B8, size=..., data=0x0, 
    ownForeignMemory=false, deleteMemory=true, __in_chrg=<optimised out>, 
    __vtt_parm=<optimised out>) at CImage.cpp:31
#2  0x00000000004c1ae0 in irr::video::CNullDriver::createImageFromData (
    this=0xb63c60, format=irr::video::ECF_A8R8G8B8, size=..., data=0x0, 
    ownForeignMemory=false, deleteMemory=true) at CNullDriver.cpp:1589
#3  0x0000000000407ef3 in savetex(irr::video::ITexture*, std::string, irr::video::IVideoDriver*) ()
#4  0x0000000000406d0d in main ()
 
 
Actually, the only thing I want is to render something with higher resolution than my display and then save it to file...
But it appears that I just cannot createImage from Textures....
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Resolution limits of the screenshots.

Post by CuteAlien »

It looks like texture->lock() returns 0. What kind of texture do you pass to savetex?
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
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

CuteAlien wrote:It looks like texture->lock() returns 0. What kind of texture do you pass to savetex?
The texture for the rendertarget.
After

Code: Select all

  video::IRenderTarget* simulatorRenderTarget = 0;
  video::ITexture* renderTargetTex = 0;
  scene::ICameraSceneNode* fixedCam = 0;
  renderTargetTex = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "RTT1", video::ECF_A8R8G8B8);
  video::ITexture* renderTargetDepth = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "DepthStencil", video::ECF_D24S8);
  simulatorRenderTarget = videoDriver->addRenderTarget();
  simulatorRenderTarget->setTexture(renderTargetTex, renderTargetDepth);
  videoDriver->setRenderTargetEx(simulatorRenderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0));
I called the function by

Code: Select all

savetex(renderTargetTex,filename,videoDriver);

And the entire cpp file is here.

Code: Select all

#include <irrlicht.h>
//#include <SIrrCreationParameters.h>
 
#include <iostream>
#include <chrono>
#include <stdio.h>
#include <stdlib.h>
 
using namespace std;
using namespace chrono;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
//This is the main method. We can now use main() on every platform.
 
void savetex(ITexture *texture, std::string filename, IVideoDriver* videoDriver) {
 
    // void* imageData = texture->lock(true);
    video::IImage* image = videoDriver->createImageFromData (
        texture->getColorFormat(),
        texture->getSize(),
        texture->lock( irr::video::E_TEXTURE_LOCK_MODE::ETLM_READ_WRITE),
        false  //copy mem
    );
 
    videoDriver->writeImageToFile(image, path(filename.c_str()));
    texture->unlock();
}
 
 
int main(int argc, char* argv[])
{
    int widthOfDisplayZone = 800;
    int heightOfDisplayZone = 600;
    int widthOfSubimage = 20;
    int heightOfSubimage = 20;
    int widthOfHole = 2;
    int heightOfHole = 2;
    video::SColor backgroundColor;
    video::SColor dotColor;
    std::string filename;
 
    bool isTesting = true;
 
    try
    {
        if (argc == 3 && std::string(argv[1])=="t")
        {
            isTesting = true;
            widthOfDisplayZone = atoi(argv[2]);
        }
        else if (argc == 2 && atoi(argv[1]) != 0)
        {
            isTesting = false;
            widthOfDisplayZone = atoi(argv[1]);
        }
        else
        {
            throw 0;
        }
    }
    catch(int error)
    {
        cout<<"Usage:\n"<<"'./pattern-irrlicht t HEIGHT' for testing images\n"<<"'./pattern-irrlicht HEIGHT' for images for using\n";
        return 0;
    }
 
 
 
 
    // Load the width and height.
    heightOfDisplayZone = widthOfDisplayZone * 210 / 297;
 
  // heightOfDisplayZone = 1024;
  // widthOfDisplayZone = 1024;
 
    if(isTesting)
    {
        backgroundColor = SColor(255,255,255,255);
        dotColor = SColor(255,0,0,0);
    }
    else
    {
        backgroundColor = SColor(255,0,0,0);
        dotColor = SColor(255,255,255,255);
    }
 
    IrrlichtDevice *device =
        createDevice(
            video::EDT_OPENGL,              //- deviceType: Type of the device. This can currently be the Null-device,one of the two software renderers, D3D8, D3D9, or OpenGL.In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL.
            //video::EDT_DIRECT3D9,
            dimension2d<u32>(widthOfDisplayZone, heightOfDisplayZone),
                                            //- windowSize: Size of the Window or screen in FullScreenMode to be created.
            16,                             //- bits: Amount of color bits per pixel.This should be 16 or 32. The parameter is often ignored when running in windowed mode.
            false,//- fullscreen: Specifies if we want the device to run in fullscreen mode or not.
            true,                           //- stencilbuffer: Specifies if we want to use the stencil buffer (for drawing shadows).
            true,                           //- vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen mode.
            0                               //- eventReceiver: An object to receive events. We do not want to use this parameter here, and set it to 0.
            );
 
 
    device->setWindowCaption(L"Light field display");
 
    IVideoDriver* videoDriver = device->getVideoDriver();
    ISceneManager* sceneManager = device->getSceneManager();
    IGUIEnvironment* guiEnvironment = device->getGUIEnvironment();
 
  video::IRenderTarget* simulatorRenderTarget = 0;
  video::ITexture* renderTargetTex = 0;
  scene::ICameraSceneNode* fixedCam = 0;
  renderTargetTex = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "RTT1", video::ECF_A8R8G8B8);
  video::ITexture* renderTargetDepth = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "DepthStencil", video::ECF_D24S8);
  simulatorRenderTarget = videoDriver->addRenderTarget();
  simulatorRenderTarget->setTexture(renderTargetTex, renderTargetDepth);
  videoDriver->setRenderTargetEx(simulatorRenderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0));
 
 
    if(isTesting)
    {
        IGUIStaticText* informationTextBox = guiEnvironment->addStaticText(L"this is text", rect<s32>(15,15,260,30), true);
        core::stringw displayStr = L"Width = ";
        displayStr += widthOfDisplayZone;
        displayStr += " Height = ";
        displayStr += heightOfDisplayZone;
        informationTextBox->setText(displayStr.c_str());
    }
 
    videoDriver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, backgroundColor);
 
 
    for (int xSubimageCount = 0; xSubimageCount < widthOfDisplayZone/widthOfSubimage; xSubimageCount++)
    {
        for (int ySubimageCount = 0; ySubimageCount < heightOfDisplayZone/heightOfSubimage; ySubimageCount++)
        {
            videoDriver->draw2DRectangle(
                dotColor,
                core::rect<s32>(
                    (xSubimageCount + 0.5) * widthOfSubimage + widthOfHole/2,
                    (ySubimageCount + 0.5) * heightOfSubimage + heightOfHole/2,
                    (xSubimageCount + 0.5) * widthOfSubimage + widthOfHole/2*3,
                    (ySubimageCount + 0.5) * heightOfSubimage + heightOfHole/2*3
                    )
                );
 
      if (xSubimageCount % 5 == 0 && ySubimageCount % 5 == 0)
      {
        IGUIStaticText* coordinatesInformationTextBox = guiEnvironment->addStaticText(
          L"this is text",
          rect<s32>(xSubimageCount * widthOfSubimage,ySubimageCount * heightOfSubimage,(xSubimageCount + 3) * widthOfSubimage, (ySubimageCount + 3) * heightOfSubimage), true);
        core::stringw displayStr = L"(";
        displayStr += xSubimageCount * widthOfSubimage;
        displayStr += ", ";
        displayStr += ySubimageCount * heightOfSubimage;
        displayStr += ")";
        coordinatesInformationTextBox->setText(displayStr.c_str());
      }
        }
    }
 
    guiEnvironment->drawAll();
    videoDriver->endScene();
 
    if(isTesting)
    {
        filename = "Img-testing-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
    }
    else
    {
        filename = "Img-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
    }
 
  // IImage * screenshot = videoDriver->createScreenShot();
    // videoDriver->writeImageToFile(screenshot, path(filename.c_str()));
  // screenshot->drop();
 
  // void* imageData = renderTargetTex->lock();
  // IImage * image = videoDriver->createImageFromData(renderTargetTex->getColorFormat(), renderTargetTex->getSize(), imageData);
  // videoDriver->writeImageToFile(image, path(filename.c_str()));
 
    savetex(renderTargetTex,filename,videoDriver);
 
  // savetex(renderTargetTex, filename, videoDriver);
  while(device->run());
}
 
I add a little bit to test, and it appears that it has been rendered to the rendertarget successfully.

Code: Select all

#include <irrlicht.h>
//#include <SIrrCreationParameters.h>
 
#include <iostream>
#include <chrono>
#include <stdio.h>
#include <stdlib.h>
 
using namespace std;
using namespace chrono;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
#endif
 
//This is the main method. We can now use main() on every platform.
 
void savetex(ITexture *texture, std::string filename, IVideoDriver* videoDriver) {
 
    // void* imageData = texture->lock(true);
    video::IImage* image = videoDriver->createImageFromData (
        texture->getColorFormat(),
        texture->getSize(),
        texture->lock( irr::video::E_TEXTURE_LOCK_MODE::ETLM_READ_WRITE),
        false  //copy mem
    );
 
    videoDriver->writeImageToFile(image, path(filename.c_str()));
    texture->unlock();
}
 
 
int main(int argc, char* argv[])
{
    int widthOfDisplayZone = 800;
    int heightOfDisplayZone = 600;
    int widthOfSubimage = 20;
    int heightOfSubimage = 20;
    int widthOfHole = 2;
    int heightOfHole = 2;
    video::SColor backgroundColor;
    video::SColor dotColor;
    std::string filename;
 
    bool isTesting = true;
 
    try
    {
        if (argc == 3 && std::string(argv[1])=="t")
        {
            isTesting = true;
            widthOfDisplayZone = atoi(argv[2]);
        }
        else if (argc == 2 && atoi(argv[1]) != 0)
        {
            isTesting = false;
            widthOfDisplayZone = atoi(argv[1]);
        }
        else
        {
            throw 0;
        }
    }
    catch(int error)
    {
        cout<<"Usage:\n"<<"'./pattern-irrlicht t HEIGHT' for testing images\n"<<"'./pattern-irrlicht HEIGHT' for images for using\n";
        return 0;
    }
 
 
 
 
    // Load the width and height.
    heightOfDisplayZone = widthOfDisplayZone * 210 / 297;
 
  // heightOfDisplayZone = 1024;
  // widthOfDisplayZone = 1024;
 
    if(isTesting)
    {
        backgroundColor = SColor(255,255,255,255);
        dotColor = SColor(255,0,0,0);
    }
    else
    {
        backgroundColor = SColor(255,0,0,0);
        dotColor = SColor(255,255,255,255);
    }
 
    IrrlichtDevice *device =
        createDevice(
            video::EDT_OPENGL,              //- deviceType: Type of the device. This can currently be the Null-device,one of the two software renderers, D3D8, D3D9, or OpenGL.In this example we use EDT_SOFTWARE, but to try out, you might want to change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D8, EDT_DIRECT3D9, or EDT_OPENGL.
            //video::EDT_DIRECT3D9,
            dimension2d<u32>(widthOfDisplayZone, heightOfDisplayZone),
                                            //- windowSize: Size of the Window or screen in FullScreenMode to be created.
            16,                             //- bits: Amount of color bits per pixel.This should be 16 or 32. The parameter is often ignored when running in windowed mode.
            false,//- fullscreen: Specifies if we want the device to run in fullscreen mode or not.
            true,                           //- stencilbuffer: Specifies if we want to use the stencil buffer (for drawing shadows).
            true,                           //- vsync: Specifies if we want to have vsync enabled, this is only useful in fullscreen mode.
            0                               //- eventReceiver: An object to receive events. We do not want to use this parameter here, and set it to 0.
            );
 
 
    device->setWindowCaption(L"Light field display");
 
    IVideoDriver* videoDriver = device->getVideoDriver();
    ISceneManager* sceneManager = device->getSceneManager();
    IGUIEnvironment* guiEnvironment = device->getGUIEnvironment();
 
  video::IRenderTarget* simulatorRenderTarget = 0;
  video::ITexture* renderTargetTex = 0;
  scene::ICameraSceneNode* fixedCam = 0;
  renderTargetTex = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "RTT1", video::ECF_A8R8G8B8);
  video::ITexture* renderTargetDepth = videoDriver->addRenderTargetTexture(core::dimension2d<u32>(widthOfDisplayZone,heightOfDisplayZone), "DepthStencil", video::ECF_D24S8);
  simulatorRenderTarget = videoDriver->addRenderTarget();
  simulatorRenderTarget->setTexture(renderTargetTex, renderTargetDepth);
  videoDriver->setRenderTargetEx(simulatorRenderTarget, video::ECBF_COLOR | video::ECBF_DEPTH, SColor(0));
 
 
    if(isTesting)
    {
        IGUIStaticText* informationTextBox = guiEnvironment->addStaticText(L"this is text", rect<s32>(15,15,260,30), true);
        core::stringw displayStr = L"Width = ";
        displayStr += widthOfDisplayZone;
        displayStr += " Height = ";
        displayStr += heightOfDisplayZone;
        informationTextBox->setText(displayStr.c_str());
    }
 
    videoDriver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, backgroundColor);
 
 
    for (int xSubimageCount = 0; xSubimageCount < widthOfDisplayZone/widthOfSubimage; xSubimageCount++)
    {
        for (int ySubimageCount = 0; ySubimageCount < heightOfDisplayZone/heightOfSubimage; ySubimageCount++)
        {
            videoDriver->draw2DRectangle(
                dotColor,
                core::rect<s32>(
                    (xSubimageCount + 0.5) * widthOfSubimage + widthOfHole/2,
                    (ySubimageCount + 0.5) * heightOfSubimage + heightOfHole/2,
                    (xSubimageCount + 0.5) * widthOfSubimage + widthOfHole/2*3,
                    (ySubimageCount + 0.5) * heightOfSubimage + heightOfHole/2*3
                    )
                );
 
      if (xSubimageCount % 5 == 0 && ySubimageCount % 5 == 0)
      {
        IGUIStaticText* coordinatesInformationTextBox = guiEnvironment->addStaticText(
          L"this is text",
          rect<s32>(xSubimageCount * widthOfSubimage,ySubimageCount * heightOfSubimage,(xSubimageCount + 3) * widthOfSubimage, (ySubimageCount + 3) * heightOfSubimage), true);
        core::stringw displayStr = L"(";
        displayStr += xSubimageCount * widthOfSubimage;
        displayStr += ", ";
        displayStr += ySubimageCount * heightOfSubimage;
        displayStr += ")";
        coordinatesInformationTextBox->setText(displayStr.c_str());
      }
        }
    }
 
    videoDriver->setRenderTargetEx(0, 0, SColor(0));
 
            videoDriver->draw2DImage(renderTargetTex,   core::position2d< s32 >(100,100));
    //  }
    // }
 
    guiEnvironment->drawAll();
    videoDriver->endScene();
 
    if(isTesting)
    {
        filename = "Img-testing-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
    }
    else
    {
        filename = "Img-" + to_string(widthOfDisplayZone) + "-" + to_string(heightOfDisplayZone) + ".png";
    }
 
  // IImage * screenshot = videoDriver->createScreenShot();
    // videoDriver->writeImageToFile(screenshot, path(filename.c_str()));
  // screenshot->drop();
 
  // void* imageData = renderTargetTex->lock();
  // IImage * image = videoDriver->createImageFromData(renderTargetTex->getColorFormat(), renderTargetTex->getSize(), imageData);
  // videoDriver->writeImageToFile(image, path(filename.c_str()));
 
    savetex(renderTargetTex,filename,videoDriver);
 
  // savetex(renderTargetTex, filename, videoDriver);
  while(device->run());
}
 
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Resolution limits of the screenshots.

Post by CuteAlien »

Oh my, our fault :-(. There is something checked into trunk right now which breaks texture-locking for rendertarget textures. Unfortunately nothing I can fix quickly, I'll inform Nadro to make this the top priority. Right now the only way around it I see is going back to older Irrlicht versions. I think it got added in version r5247, so version before that should still be fine.
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
lvgeng
Posts: 38
Joined: Fri Aug 14, 2015 4:35 pm

Re: Resolution limits of the screenshots.

Post by lvgeng »

CuteAlien wrote:Oh my, our fault :-(. There is something checked into trunk right now which breaks texture-locking for rendertarget textures. Unfortunately nothing I can fix quickly, I'll inform Nadro to make this the top priority. Right now the only way around it I see is going back to older Irrlicht versions. I think it got added in version r5247, so version before that should still be fine.
:shock: Well... Thank you very much and at least now I know it is something I cannot solve by trying different ways... And I am glad that a bug was found... (if it is a bug, I mean, sometime it is really hard to draw the line...)
:( Although I might need to find another way to do so or try another version of trunk... time to go back towards the beginning a little bit.

PS: Although it is strongly not recommended but I still feel the option for a 16bit stencil buffer would be really helpful in some situation... do we have a plan to add it?
PSS: svn is really a nightmare for such a long term project... it took me almost half an hour to fetch the repository...
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Resolution limits of the screenshots.

Post by CuteAlien »

Sorry, not sure about stencil-buffer. Nadro is currently working on that kind of stuff and before it was Hybrid - I never really worked on that.
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