Home » U++ Library support » U++ Widgets - General questions or Mixed problems » Taking snapshot of GLCtrl no longer works
Taking snapshot of GLCtrl no longer works [message #52184] |
Mon, 05 August 2019 12:20 |
Tom1
Messages: 1251 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
I have not worked with GLCtrl for a while. Now as I tried to recompile my old program, I found out that my code taking snapshot of the GLCtrl contents no longer works. It just returns a black image:
Size sz=GetSize();
ImageBuffer ib(sz);
glReadPixels(0,0,sz.cx,sz.cy,GL_BGRA_EXT,GL_UNSIGNED_BYTE,(GLvoid*)(RGBA*)ib);
Any suggestions how to proceed?
Best regards,
Tom
|
|
|
Re: Taking snapshot of GLCtrl no longer works [message #52192 is a reply to message #52184] |
Wed, 07 August 2019 14:50 |
Tom1
Messages: 1251 Registered: March 2007
|
Senior Contributor |
|
|
Hi,
I just cannot get around this issue for some reason. When I call glGetError(), it simply returns GL_INVALID_OPERATION.
I'm not in a middle of a glBegin/glEnd -pair either. The code worked/works on Upp svn 11960, and I have tried many options for format parameter here without any success.
I guess this is somehow related to the changes done to GLCtrl some time ago, but I cannot see the relevant change compared to the previous version.
BTW, I'm working on Windows 10 x64.
Any help will be appreciated!
Best regards,
Tom
|
|
|
|
|
|
Re: Taking snapshot of GLCtrl no longer works [message #52212 is a reply to message #52207] |
Fri, 09 August 2019 11:00 |
Tom1
Messages: 1251 Registered: March 2007
|
Senior 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
|
|
|
|
|
|
Re: Taking snapshot of GLCtrl no longer works [message #52222 is a reply to message #52221] |
Mon, 12 August 2019 07:42 |
Tom1
Messages: 1251 Registered: March 2007
|
Senior Contributor |
|
|
Hi Koldo,
Have you tried to call 'glGetError()' just before taking the snapshot? This would clear any errors prior to calling 'glReadPixels()'. Since you can get the actual snapshot done, it does not sound logical the 'glReadPixels()' would be the one to fail with GL_INVALID_OPERATION. (Just for reference, I do not get GL_INVALID_OPERATION here. Running on latest Windows 10 x64 with Intel Core i9 integrated graphics.)
Best regards,
Tom
|
|
|
|
|
|
Re: Taking snapshot of GLCtrl no longer works [message #52234 is a reply to message #52232] |
Tue, 13 August 2019 09:07 |
Tom1
Messages: 1251 Registered: March 2007
|
Senior Contributor |
|
|
Hi Mirek,
Maybe that is a good idea, actually before calling GLExecute() and GLPaint() too. However, the GLExecute() and GLPaint() should only be called if glGetError() does not have any errors pending from its own initialization. This way we can always trust in GLExecute() and GLPaint() that the initialization of GL has been successful and any GL errors are due to our own code. This may require something to handle errors inside GLCtrl.
Best regards,
Tom
|
|
|
Goto Forum:
Current Time: Fri Nov 01 00:45:59 CET 2024
Total time taken to generate the page: 0.05338 seconds
|