i have qopenglwidget in draw text qpainter. implement snapshot feature rendering widget content qopenglframebuffer , converting frame buffer qimage.
unfortunately, if set font's point size high (> 46), text appears black bar in snapshot, while in widget displayed correctly. see below example snapshot block on line supposed text font size > 46. 
here simplified code render image (it should work, because correctly displayed in qopenglwidget):
void rendersomething(const int x, const int y, const qstring & str, const int fontsize) { // 1. draw line // (calculate min_x, max_x, y , z values) gllinewidth(3); glcolor3f(0., 0., 0.); glbegin(gl_lines); glvertex3f(min_x, y, z); glvertex3f(max_x, y, z); glend(); // 2. draw text glint gl_viewport[4]; glgetintegerv(gl_viewport, gl_viewport); backup_gl_state(); qopenglpaintdevice paintdevice(gl_viewport[2], gl_viewport[3]); qpainter painter(&paintdevice); painter.setfont(qfont(painter.font().family(), fontsize); painter.setpen(qt::black); painter.drawtext(x, y, str); painter.end(); restore_gl_state(); } here code storing snapshot:
void viewport::takesnapshot(const qstring & path, const int size) { glpushattrib(gl_viewport_bit); glviewport(0, 0, size, size); // since size varies want text scale qopenglframebufferobject fbo(size, size, qopenglframebufferobject::depth); fbo.bind(); glclear(gl_color_buffer_bit | gl_depth_buffer_bit); renderer.rendersomething(100, 100, "test", 50); // here render call! qimage fboimage(fbo.toimage()); qimage image(fboimage.constbits(), fboimage.width(), fboimage.height(), qimage::format_rgb32); image.save(path); glpopattrib(); fbo.binddefault(); fbo.release(); } edit
i found workaround using qpainter directly draw text on qimage instead of drawing fbo. no black bar anymore, complicates code , happy find real solution...
the solution simple: re-read the documentation on qopenglframebufferobject in says:
create qopenglframebufferobject instance combineddepthstencil attachment if want qpainter render correctly.
i attached depth buffer. correct initialization be:
qopenglframebufferobject fbo(size, size, qopenglframebufferobject::combineddepthstencil);
Comments
Post a Comment