About Store Forum Documentation Contact



Post Reply 
Render to image problem
Author Message
Pherael Offline
Member

Post: #1
Render to image problem
I was using this code to capture low size preview image for my save game data, but after new update it stopped working - now image is all black

Code:
void RenderToTexture(Image &img)
{
   D.clear(BLACK);
   D.viewRect(&RectI(0, 0, 256, 192));              
   Renderer(Render);
   Renderer.capture(img, -1, -1, IMAGE_R8G8B8A8_SRGB, IMAGE_2D, 0);
   img.crop(img, 0, 0, 256, 192);    
   D.viewRect(null);
}

So I check tutorials and create new function:

Code:
void RenderToTexture(Image &img)
{
   int tex_size=256;
   rtt.create(VecI2(tex_size, tex_size), IMAGE_R8G8B8A8_SRGB);
   rtp=&rtt;
   // render to texture
   Renderer.target=&rtt;  // specify custom render target
   Renderer(Render);     // perform rendering
   Renderer.target=null; // disable custom render target
   img.copy(rtt);
}

But it's also dosn't work, it's not possible to copy ImgeRT to Image? Or I making mistake somewhere else? Or can I just use ImageRT as normal Image?
(This post was last modified: 08-26-2019 02:49 PM by Pherael.)
08-26-2019 02:47 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Render to image problem
It's possible to copy ImageRT to Image. But you don't have to. You can use it straight away as image.
Your second code calls image copy, probably in wrong order. Isn't the parameter the dest reference?
I'll check your codes tomorrow in the morning
08-26-2019 05:01 PM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #3
RE: Render to image problem
Ah, yes! You right, silly me. It should be rtt.copy(img). Thank you!
(This post was last modified: 08-26-2019 08:15 PM by Pherael.)
08-26-2019 08:14 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Render to image problem
Code:
D.clear(BLACK);
   D.viewRect(&RectI(0, 0, 256, 192));              
   Renderer(Render);
   Renderer.capture(img, -1, -1, IMAGE_R8G8B8A8_SRGB, IMAGE_2D, 0);
   img.crop(img, 0, 0, 256, 192);    
   img.Export("C:/!/0.bmp");
   D.viewRect(null);
I've tested this code however it works OK.
BTW. I think you need just 1 mip instead of 0(full set).
08-27-2019 04:33 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #5
RE: Render to image problem
So I use this simple code, and get Image I added in attachment. Render is my main rendering function I use for my game (it should only draw 3d stuff).

D.clear(BLACK);
D.viewRect(&RectI(0, 0, 256, 192));
Renderer(Render);
Renderer.capture(img, -1, -1, IMAGE_R8G8B8A8_SRGB, IMAGE_2D, 1);
img.Export("C:/Esenthel/0.png");


Attached File(s) Image(s)
   
(This post was last modified: 08-27-2019 09:12 AM by Pherael.)
08-27-2019 09:11 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Render to image problem
this looks like artifacts from 'ImageRT.discard'

Are you calling this code inside Draw or Update?
Are you on Windows platform? Classic Win32 or UWP?

I've tested this again (Win32) however it works fine for me. Tested on 2 GPU's

https://esenthel.com/?id=doc#Thread_Safety
Quote:Drawing
All drawing/rendering functions should be called only on the main thread, inside current State Draw function, which is called automatically by the engine.
08-27-2019 09:22 AM
Find all posts by this user Quote this message in a reply
Pherael Offline
Member

Post: #7
RE: Render to image problem
Yes, I check it and indeed I was using it until now in Update, since I needed it while I was creating save file. I never put much tought about it, since it was working well for like a year on many computers without any issues (wierd grin). Thank you for you support, I will move it to proper State function.
08-27-2019 09:52 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #8
RE: Render to image problem
Older GPU's don't have 'ImageRT.discard' support.
So this affects only new GPU's.
Also in new engine version I've made some additional 'discard' call changes to improve performance.
If that won't help, then please let me know.
08-27-2019 09:54 AM
Find all posts by this user Quote this message in a reply
Post Reply