From b294a013e6ccd5d6ffdbfe4c626a21789ef43632 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 9 Aug 2019 10:55:01 +0000 Subject: [PATCH] .reference git-svn-id: svn://ultimatepp.org/upp/trunk@13531 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- reference/OpenGL/main.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/reference/OpenGL/main.cpp b/reference/OpenGL/main.cpp index 9f10cd36c..bbf769177 100644 --- a/reference/OpenGL/main.cpp +++ b/reference/OpenGL/main.cpp @@ -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 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();