Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Taking snapshot of GLCtrl no longer works
Re: Taking snapshot of GLCtrl no longer works [message #52212 is a reply to message #52207] |
Fri, 09 August 2019 11:00   |
Tom1
Messages: 1303 Registered: March 2007
|
Ultimate Contributor |
|
|
Hi Mirek,
Yes, thanks! This ExecuteGL approach works beautifully. Could you add this to Linux and OSX too? (Although, I still don't have any of those Macs.)
Here's how to get the snapshot:
String exportdir;
virtual void ExportViewAsImage(){
Size sz=GetSize();
ImageBuffer ib(sz);
glReadPixels(0,0,sz.cx,sz.cy,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(GLvoid*)~ib);
if(!glGetError()){
// Flip
Buffer<RGBA> temp(sz.cx);
for(int i=0;i<sz.cy/2;i++){
memcpy(temp,ib[i],sz.cx*sizeof(RGBA));
memcpy(ib[i],ib[sz.cy-1-i],sz.cx*sizeof(RGBA));
memcpy(ib[sz.cy-1-i],temp,sz.cx*sizeof(RGBA));
}
// Flatten alpha channel
for(int i=0;i<sz.cy;i++){
for(int x=0;x<sz.cx;x++) ib[i][x].a=255;
}
// Save image
FileSel fs;
fs.Type("Portable Network Graphics (*.png)","*.png");
if(!exportdir.IsEmpty()) fs.PreSelect(exportdir);
else fs.ActiveDir(::GetDesktopFolder());
if(fs.ExecuteSaveAs("Save snapshot as...")){
exportdir=~fs;
PNGEncoder enc;
enc.SaveFile(~fs,ib);
}
}
}
void ContextMenu(Bar& bar) {
bar.Add("Export view as image...", [&](){ ExecuteGL(THISFN(ExportViewAsImage)); });
}
Thanks and best regards,
Tom
|
|
|
 |
|
Taking snapshot of GLCtrl no longer works
By: Tom1 on Mon, 05 August 2019 12:20
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Wed, 07 August 2019 14:50
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Wed, 07 August 2019 16:45
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: mirek on Fri, 09 August 2019 09:13
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: mirek on Fri, 09 August 2019 09:26
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Fri, 09 August 2019 11:00
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Fri, 09 August 2019 14:00
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: mirek on Fri, 09 August 2019 16:29
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Mon, 12 August 2019 08:52
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: koldo on Sun, 11 August 2019 18:45
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Mon, 12 August 2019 07:42
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: koldo on Mon, 12 August 2019 16:00
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: mirek on Mon, 12 August 2019 21:50
|
 |
|
Re: Taking snapshot of GLCtrl no longer works
By: Tom1 on Tue, 13 August 2019 09:07
|
Goto Forum:
Current Time: Mon Jun 16 03:55:39 CEST 2025
Total time taken to generate the page: 0.04977 seconds
|