QT FBO
QOenGLFrameBufferObjectこれはinitializeOpenGLFunctions()の後になります
framebuffer=new QOpenGLFramebufferObject(w,h, QOpenGLFramebufferObject::Depth);
このframebuffer->bind();release();
framebuffer=new QOpenGLFramebufferObject(w,h, QOpenGLFramebufferObject::Depth);
このframebuffer->bind();release();
void MainWidget::paintGL()
{
texture->bind();
bool result=framebuffer->bind();
if(result)
// Clear color and depth buffer
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//! [6]
// Calculate model view transformation
QMatrix4x4 matrix;
QMatrix4x4 view;
view.lookAt(QVector3D(0,0,1.0),QVector3D(0,0.0,0.0),QVector3D(0,1.0,0.0));
QVector3D lightPos(3.0f,0.0f,0.0f);
{ // Draw cube geometry
{
// Bind shader pipeline for use
if (!program.bind())
{close();}
matrix.translate(-1.0,0.0, -5.0);
matrix.rotate(rotation);
QMatrix4x4 model=matrix;
QMatrix4x4 transpose_inverse_model=model.inverted().transposed();
program.setUniformValue("model",model);
program.setUniformValue("transpose_inverse_model",transpose_inverse_model);
program.setUniformValue("mvp_matrix", projection *view* matrix);
// Use texture unit 0 which contains cube.png
program.setUniformValue("texture", 0);
//program.setUniformValue("objectColor", 1.0f, 0.5f, 0.31f);
program.setUniformValue("lightColor", 1.0f, 0.5f, 1.0f);
program.setUniformValue("lightPos",lightPos);
program.setUniformValue("viewPos",QVector3D(0,0,1.0));
geometries->drawCubeGeometry(&program);
}
{
if (!program2.bind())
{close();}
//texture->bind();
QMatrix4x4 m2;
m2.translate(3.0, 0.0, -0.0);
m2.scale(QVector3D(0.5,0.5,0.5));
program2.setUniformValue("mvp_matrix", projection* m2);
geometries->drawCubeGeometry(&program2);
}
}
GLuint tid=framebuffer->texture();
framebuffer->release();
glBindTexture(GL_TEXTURE_2D, tid);
view.lookAt(QVector3D(0,0,1.0),QVector3D(0,0.0,0.0),QVector3D(0,1.0,0.0));
{
{
// Bind shader pipeline for use
if (!program.bind())
{close();}
matrix.translate(-1.0,0.0, -5.0);
matrix.rotate(rotation);
QMatrix4x4 model=matrix;
QMatrix4x4 transpose_inverse_model=model.inverted().transposed();
program.setUniformValue("model",model);
program.setUniformValue("transpose_inverse_model",transpose_inverse_model);
program.setUniformValue("mvp_matrix", projection *view* matrix);
// Use texture unit 0 which contains cube.png
program.setUniformValue("texture", 0);
//program.setUniformValue("objectColor", 1.0f, 0.5f, 0.31f);
program.setUniformValue("lightColor", 1.0f, 0.5f, 1.0f);
program.setUniformValue("lightPos",lightPos);
program.setUniformValue("viewPos",QVector3D(0,0,1.0));
geometries->drawCubeGeometry(&program);
}
{
// program.release();
//Link shader pipeline
//program.destroyed();
if (!program2.bind())
{close();}
//texture->bind();
QMatrix4x4 m2;
m2.translate(3.0, 0.0, -0.0);
m2.scale(QVector3D(0.5,0.5,0.5));
//matrix.rotate(rotation);
program2.setUniformValue("mvp_matrix", projection* m2);
geometries->drawCubeGeometry(&program2);
}
}
}
glBindTexture(GL_TEXTURE_2D,0);
}