Exporting images from ZGE

All topics about ZGameEditor goes here.

Moderator: Moderators

User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Exporting images from ZGE

Post by Ats »

Hi,

I'd like to make some animated gif from rotating models in ZGE.
Is it possible to export some frames to png or another image format?
Or do I have to use an external recording software?

Thanks!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Exporting images from ZGE

Post by Kjell »

Hi Ats,
Ats wrote:I'd like to make some animated gif from rotating models in ZGE.
If you want to do a clean & consistent rotating GIF it's best to capture the frames from ZGE itself.
Ats wrote:Is it possible to export some frames to png or another image format?
Such feature is not built-in, but it's pretty easy to do by yourself .. attached is a example ( press F to save a frame ) and below is the generated GIF ( from the captured frames ).

Image

K
Attachments
Capture.zgeproj
(3.64 KiB) Downloaded 838 times
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

I finally had the time to use your image exporter.
But I didn't think that it would take that much time for the processor to make a capture :shock:

I've made some rotating ships and stuff:
Image Image Image
Image Image Image

;) Thank you!
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,
Ats wrote:I didn't think that it would take that much time for the processor to make a capture
How long does it take to capture a frame on your computer? I get about 15 TGAs per second when i set the KeyPress.RepeatDelay of the Capture example to 0.

By the way, the fighter and interceptor GIFs contain duplicate frames ( the first frame is identical to the last one ) which causes the "hiccup" after each rotation.

And personally i would have gone with flat shading, but that's just a artistic choice :wink:

K
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Post by Ats »

mmm... Even with the KeyPress.RepeatDelay set to 0, it takes almost 3 seconds per frame on your ZGE project to make a capture...
I'm using an Asus Transformer T100 (http://www.engadget.com/products/asus/t ... 100/specs/).

For the flat shading, you are totally right. I'm working on this game from time to time for so long that I don't even remember why I went with smooth shading... I'll make new gif this afternoon :)

Edit: Oh yeah, now I'm remember, that was for the asteroïds. So I'm keeping smooth material only for them.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi Ats,
Ats wrote:Even with the KeyPress.RepeatDelay set to 0, it takes almost 3 seconds per frame on your ZGE project to make a capture.
That's outrageously slow :? Just tried it on a 10 year old laptop ( with Intel GPU ) and still get 7 frames per second ( held the F key down for a minute and got 422 TGAs ). Are you running anti-virus software or something?

K
User avatar
rrTea
Posts: 475
Joined: Sat Feb 15, 2014 9:54 am

Post by rrTea »

It's similarly slow on my 4 or so years old computer too, especialy if the resolution of a project is a bit "higher" (800*600). But I don't particularly mind: it works and it's useful to have it built in. Thanks!

Acer Aspire M3970
Interl i5-2320 @ 3.00GHz
8.00GB
NVidia GeForce GT520 353.06
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Exporting images from ZGE

Post by Ats »

I'm back at taking screenshots.
So I'm digging through Capture.zgeproj and I have some questions:

How do we know that the exported image is a tga, other than by setting that in the file name?

Code: Select all

FrameFile.FileName = "Frame" + (Frame < 10 ? "0" : "") + intToStr(Frame) + ".tga";
Could that be a friendlier format, like bmp or png?

Is there a size limit for FrameBuffer.SizeDim1? Could 1280x1024 fit in that?

Code: Select all

FrameBuffer.SizeDim1 = FrameWidth * FrameHeight << 2;
Edit: Seems like it does. The problem was coming from my next problem:

Not every exported images are readable. And sometimes the file size can vary (a lot) from one image to another, even if I deactivate the diamond rotation so the images are exactly the same.

Edit: Seems that last one is Dropbox's fault. Since I'm working inside the synchronized Dropbox folder, I had to deactivate it in order to obtain correct screenshot files.
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Exporting images from ZGE

Post by Kjell »

Hi Ats,
Ats wrote:How do we know that the exported image is a tga, other than by setting that in the file name?
Each file format stores data in a specific way .. just changing the file extension from TGA into BMP or PNG doesn't magically transform the data inside the file.
Ats wrote:Could that be a friendlier format, like bmp or png?
The reason why i went with TGA is because it's a very simple file format. You could write a exporter for BMP or PNG as well, but especially PNG is quite a bit of work.

K
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Exporting images from ZGE

Post by VilleK »

I needed a non-component version of this routine so I'm posting it here for future reference. This routine also need the OpenGL ZExternalLibrary from Kjells project.

Code: Select all

void saveScreenDump(string filename) {
  //Based on code by Kjell http://www.emix8.org/forum/viewtopic.php?f=1&t=1156&p=7242&hilit=save+image#p7242
  int w=App.ViewportWidth;
  int h=App.ViewportHeight;

  byte[18] header;

  header[2] = 2;
  header[16] = 32;
  header[17] = 8;

  header[12] = w;
  header[13] = w >> 8;

  header[14] = h;
  header[15] = h >> 8;

  byte[] buffer;
  buffer.SizeDim1 = header.SizeDim1 + w*h*4;

  int dst=0;
  for(int i=0; i<header.SizeDim1; i++)
    buffer[dst++]=header[i];

  glReadPixels(App.ViewportX, App.ViewportY, w, h, 0x80E1, 0x1401, buffer[dst]);

  @FileAction( File : @File(FileName : filename, Encoding : 1, TargetArray : buffer), Action : 1 );
}
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Exporting images from ZGE

Post by Ats »

Hi VilleK, did something critical changed in ZGE since last july?
Exporting images from ZGE as a TGA file don't work anymore. The file is created, but isn't recognized as anything :?
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: Exporting images from ZGE

Post by VilleK »

Ats wrote: Sun Mar 14, 2021 8:19 pm Hi VilleK, did something critical changed in ZGE since last july?
Exporting images from ZGE as a TGA file don't work anymore. The file is created, but isn't recognized as anything :?
It should work. Did you try my non-component version above? I used it two weeks ago and it was working fine.
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Exporting images from ZGE

Post by Ats »

Nope. Then I guess it will work, I'm trying now.
But the previous one with the component isn't working anymore

Edit:
All right, your version is working perfectly and is almost instantaneous, while the previous one took many seconds per image. Perfect!
User avatar
Ats
Posts: 603
Joined: Fri Sep 28, 2012 10:05 am
Contact:

Re: Exporting images from ZGE

Post by Ats »

Since I have Delphi installed, I compiled that pascal TGA2PNG converter: https://github.com/shusaura85/tga2png
It's working nicely just by dropping the tga on the exe.
The reason why i went with TGA is because it's a very simple file format. You could write a exporter for BMP or PNG as well, but especially PNG is quite a bit of work.
I took a look it's source code, and now I understand what you meant :lol:
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: Exporting images from ZGE

Post by Kjell »

Hi Ats,
Ats wrote: Thu Apr 22, 2021 9:12 amI took a look it's source code, and now I understand what you meant :lol:
That project only contains TGA related code though? It uses the PNGImage unit ( which comes with Delphi / FreePascal ) to encode the PNG.

K
Post Reply