画在QGLFrameBufferObject [英] Draw in QGLFrameBufferObject
问题描述
使用Qt和opengl,我想画一个QGlFrameBufferObject吗? 我尝试这个:
With Qt and opengl, I would like draw in a QGlFrameBufferObject ? I try this :
QGLFrameBufferObject * fbo = new QGLFramebufferObject(200, 200, QGLFramebufferObject::NoAttachment, GL_TEXTURE_2D, GL_RGBA32F);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0f, fbo->size().width(), fbo->size().height(), 0.0f, 0.0f, 1.0f);
fbo->bind();
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
fbo->release();
fbo->toImage().save("test.jpg"));
但是我没有得到红色图像.
But I don't get a red image.
其他问题
如果我想用:
glBegin(GL_QUAD);
glColor3d(0.2, 0.5, 1.0);
glVertex2i( 10, 20);
glColor3d(0.7, 0.5, 1.0);
glVertex2i( 15, 20);
glColor3d(0.8, 0.4, 1.0);
glVertex2i( 15, 25);
glColor3d(0.1, 0.9, 1.0);
glVertex2i( 10, 25);
glEnd();
我还需要glClear()
吗?
推荐答案
您从未真正清除帧缓冲区. glClearColor()
仅设置用于清除的颜色,但不清除任何内容.您将需要在此处添加第二行:
You never actually clear the framebuffer. glClearColor()
only sets the color used for clearing, but does not clear anything. You will need to add the second line here:
glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glClear()
调用将使用您在第一个调用中指定的透明颜色清除颜色缓冲区.帧缓冲区的内容最初是不确定的,因此在开始绘制之前,应始终使用glClear()
调用清除帧缓冲区.唯一的例外是,如果您确定所渲染的图元将覆盖绘图表面的每个像素.即使这样,在某些体系结构上,实际上仍然可以先调用glClear()
来提高性能.
The glClear()
call will clear the color buffer with the clear color you specified in the first call. The framebuffer content is initially undefined, so you should always clear the framebuffer with a glClear()
call before you start drawing. The only exception is if you're certain that the primitives you render will cover every pixel of the drawing surface. Even then, on some architectures it can actually be better for performance to still call glClear()
first.
只要您清除缓冲区,就没关系了.但是一旦要开始绘制,就还需要设置视口:
It shouldn't matter yet as long as you only clear the buffer. But once you want to start drawing, you will also need to set the viewport:
glViewport(0, 0, 200, 200);
这篇关于画在QGLFrameBufferObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!