QOpenGLFramebufferObjectFormat :: toImage()Android黑色图片

时间:2015-05-31 14:11:42

标签: android qt opengl-es

我正在Android设备上尝试https://dangelog.wordpress.com/2013/02/10/using-fbos-instead-of-pbuffers-in-qt-5-2/的代码。

经过一些更改以使代码正常运行,我无法获得正确的图像。在Android上,图像完全是黑色的。我究竟做错了什么?谢谢!

这里是第一行的变化:

QSurfaceFormat format;
format.setMajorVersion(2);
format.setMinorVersion(2);

QOffscreenSurface window;
//window.setSurfaceType(QWindow::OpenGLSurface);
window.setFormat(format);
window.create();

QOpenGLContext* context=(QOpenGLContext::currentContext());

// context.setFormat(format);
/* if (!context.create())
    qFatal("Cannot create the requested OpenGL context!");
*/
context->makeCurrent(&window);

const QRect drawRect(0, 0, 400, 400);
const QSize drawRectSize = drawRect.size();

QOpenGLFramebufferObjectFormat fboFormat;
//fboFormat.setSamples(16);
//fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);

QOpenGLFramebufferObject fbo(drawRectSize, fboFormat);
fbo.bind();

更新1 我将代码更改为

QSurfaceFormat format;
format.setMajorVersion(3);
format.setMinorVersion(0);

char* extensionList = (char*) glGetString(GL_VERSION);
qDebug()<<extensionList;
QOffscreenSurface window;
//QOffscreen is always an OpenGLSurface 
//window.setSurfaceType(QWindow::OpenGLSurface); 
window.setFormat(format);
window.create();

//QOpenGLContext* context=(QOpenGLContext::currentContext());

QOpenGLContext context;
context.setFormat(format);
if (!context.create())
    qFatal("Cannot create the requested OpenGL context!");

if(!context.makeCurrent(&window))
    qFatal("Cannot makecurrent(windows)!");

但它没有改变结果......我仍然得到一个黑色的png图像。我检查了Qimage的格式,它似乎是正确的(ARG32,它对应于fbo GL_RGBA的格式)。

0 个答案:

没有答案