Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Export generates black image #415

Closed
nabijaczleweli opened this issue May 20, 2019 · 6 comments
Closed

Image Export generates black image #415

nabijaczleweli opened this issue May 20, 2019 · 6 comments
Milestone

Comments

@nabijaczleweli
Copy link
Contributor

System information

SolveSpace version: 3.0~62aba398

Operating system: Windows 10

Expected behavior

The File -> Export Image… menu item, after confirming location, exports the visible geometry.

Actual behavior

The output file has the correct size, but contains only black.

Additional information

Works on 2.3.

Doesn't depend on the contents of the sketch.

@whitequark
Copy link
Contributor

The bug is likely related to this function:

std::shared_ptr<Pixmap> OpenGl3Renderer::ReadFrame() {
std::shared_ptr<Pixmap> pixmap =
Pixmap::Create(Pixmap::Format::RGB, (size_t)camera.width, (size_t)camera.height);
glReadPixels(0, 0, (int)camera.width, (int)camera.height,
GL_RGB, GL_UNSIGNED_BYTE, &pixmap->data[0]);
return pixmap;
}

On Windows, ANGLE is used, which might have some issue with glReadPixels. That said, I'm pretty sure I tested it before and it worked...

@nabijaczleweli
Copy link
Contributor Author

Following the lead from this SO answer, I applied the following patch:

diff --git a/src/render/rendergl3.cpp b/src/render/rendergl3.cpp
index 167ce03..cc21130 100644
--- a/src/render/rendergl3.cpp
+++ b/src/render/rendergl3.cpp
@@ -5,6 +5,7 @@
 //-----------------------------------------------------------------------------
 #include "solvespace.h"
 #include "gl3shader.h"
+#include <fstream>

 namespace SolveSpace {

@@ -679,10 +680,25 @@ void OpenGl3Renderer::Clear() {
 }

 std::shared_ptr<Pixmap> OpenGl3Renderer::ReadFrame() {
+    std::ofstream err("t:/solvespace-err.log");
+    err << std::hex;
+
     std::shared_ptr<Pixmap> pixmap =
         Pixmap::Create(Pixmap::Format::RGB, (size_t)camera.width, (size_t)camera.height);
+
+    err << "pregl\n";
+    for(GLenum e; (e = glGetError()) != GL_NO_ERROR;) {
+        err << e << '\n';
+    }
+
     glReadPixels(0, 0, (int)camera.width, (int)camera.height,
                  GL_RGB, GL_UNSIGNED_BYTE, &pixmap->data[0]);
+
+    err << "postgl\n";
+    for(GLenum e; (e = glGetError()) != GL_NO_ERROR;) {
+        err << e << '\n';
+    }
+
     return pixmap;
 }

And, after Exporting Image, the contents of t:/solvespace-err.log are

pregl
postgl
502

Which this says is GL_INVALID_OPERATION.

Sadly, I don't really do GL et al. so I don't know where to follow with this.

@whitequark
Copy link
Contributor

From the OpenGL ES 2 doc:

GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_SHORT_5_6_5 and format is not GL_RGB.

GL_INVALID_OPERATION is generated if type is GL_UNSIGNED_SHORT_4_4_4_4 or GL_UNSIGNED_SHORT_5_5_5_1 and format is not GL_RGBA.

GL_INVALID_OPERATION is generated if format and type are neither GL_RGBA and GL_UNSIGNED_BYTE, respectively, nor the format/type pair returned by querying GL_IMPLEMENTATION_COLOR_READ_FORMAT and GL_IMPLEMENTATION_COLOR_READ_TYPE.

@whitequark
Copy link
Contributor

I believe this is fixed in 11c5cdc. Can you check?

@nabijaczleweli
Copy link
Contributor Author

And so it is! Thank you!

export

@whitequark
Copy link
Contributor

Very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants