.reference

git-svn-id: svn://ultimatepp.org/upp/trunk@13531 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2019-08-09 10:55:01 +00:00
parent 9e63c8d960
commit b294a013e6

View file

@ -60,6 +60,34 @@ struct OpenGLExample : GLCtrl {
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
}
virtual void LeftDown(Point, dword)
{ // Demonstrates how to create a screenshot of opengl widget
ExecuteGL([&] {
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(RGBA& t : ib)
t.a = 255;
// Save image
String p = SelectFileSaveAs("Portable Network Graphics (*.png)\t*.png");
if(p.GetCount())
PNGEncoder().SaveFile(p, ib);
}
});
}
virtual void MouseMove(Point p, dword) {
point = p;
Refresh();