can't you test your fbo instructions separately in another program? You may also have a look at my own fbo implementation sample (ignore the lighting part of the program):
void GlWidget::paintGL()
{
BakeDynamicTexture();
// RenderShapes();
glClearColor(0, 0, 0.0f, 1.0f);
// //! [2]
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width(),height());
QMatrix4x4 mMatrix;
QMatrix4x4 vMatrix;
QMatrix4x4 cameraTransformation;
cameraTransformation.rotate(alpha, 0, 1, 0);
cameraTransformation.rotate(beta, 1, 0, 0);
QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
QMatrix4x4 mvMatrix;
mMatrix.setToIdentity();
mvMatrix = vMatrix * mMatrix;
QMatrix3x3 normalMatrix;
normalMatrix = mvMatrix.normalMatrix();
QMatrix4x4 lightTransformation;
lightTransformation.rotate(lightAngle, 0, 1, 0);
QVector3D lightPosition = lightTransformation * QVector3D(0, 1, 1);
//! [3]
//##########################
// lightingShaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
// shpFill->RenderCube (&lightingShaderProgram, dynamicTexture);
// lightingShaderProgram.release();
//##########################
//! [5]
lightingShaderProgram.bind();
lightingShaderProgram.setUniformValue("mvpMatrix", pMatrix * mvMatrix);
lightingShaderProgram.setUniformValue("mvMatrix", mvMatrix);
lightingShaderProgram.setUniformValue("normalMatrix", normalMatrix);
lightingShaderProgram.setUniformValue("lightPosition", vMatrix * lightPosition);
shpFill->RenderLightingCube(&lightingShaderProgram, dynamicTexture);
mMatrix.setToIdentity();
mMatrix.translate(lightPosition);
mMatrix.rotate(lightAngle, 0, 1, 0);
mMatrix.rotate(45, 1, 0, 0);
mMatrix.scale(0.1);
coloringShaderProgram.bind();
coloringShaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
shpFill->colorLightingCube(&coloringShaderProgram);
}
void GlWidget::paintGL()
{
BakeDynamicTexture();
// RenderShapes();
glClearColor(0, 0, 0.0f, 1.0f);
// //! [2]
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width(),height());
QMatrix4x4 mMatrix;
QMatrix4x4 vMatrix;
QMatrix4x4 cameraTransformation;
cameraTransformation.rotate(alpha, 0, 1, 0);
cameraTransformation.rotate(beta, 1, 0, 0);
QVector3D cameraPosition = cameraTransformation * QVector3D(0, 0, distance);
QVector3D cameraUpDirection = cameraTransformation * QVector3D(0, 1, 0);
vMatrix.lookAt(cameraPosition, QVector3D(0, 0, 0), cameraUpDirection);
QMatrix4x4 mvMatrix;
mMatrix.setToIdentity();
mvMatrix = vMatrix * mMatrix;
QMatrix3x3 normalMatrix;
normalMatrix = mvMatrix.normalMatrix();
QMatrix4x4 lightTransformation;
lightTransformation.rotate(lightAngle, 0, 1, 0);
QVector3D lightPosition = lightTransformation * QVector3D(0, 1, 1);
//! [3]
//##########################
// lightingShaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
// shpFill->RenderCube (&lightingShaderProgram, dynamicTexture);
// lightingShaderProgram.release();
//##########################
//! [5]
lightingShaderProgram.bind();
lightingShaderProgram.setUniformValue("mvpMatrix", pMatrix * mvMatrix);
lightingShaderProgram.setUniformValue("mvMatrix", mvMatrix);
lightingShaderProgram.setUniformValue("normalMatrix", normalMatrix);
lightingShaderProgram.setUniformValue("lightPosition", vMatrix * lightPosition);
shpFill->RenderLightingCube(&lightingShaderProgram, dynamicTexture);
mMatrix.setToIdentity();
mMatrix.translate(lightPosition);
mMatrix.rotate(lightAngle, 0, 1, 0);
mMatrix.rotate(45, 1, 0, 0);
mMatrix.scale(0.1);
coloringShaderProgram.bind();
coloringShaderProgram.setUniformValue("mvpMatrix", pMatrix * vMatrix * mMatrix);
shpFill->colorLightingCube(&coloringShaderProgram);
}
To copy to clipboard, switch view to plain text mode
Baking part:
void GlWidget::BakeDynamicTexture()
{
fbo->bind();
RenderShapes();
fbo->release();
dynamicTexture = fbo->texture();
}
void GlWidget::BakeDynamicTexture()
{
fbo->bind();
RenderShapes();
fbo->release();
dynamicTexture = fbo->texture();
}
To copy to clipboard, switch view to plain text mode
RenderShapes (instead of drawing a shape file here, simply draw something else, check if it draws successfully)
void GlWidget::RenderShapes()
{
QMatrix4x4 sMatrix;
glClearColor(0.1f, 0.5f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 256,256);
shaderProgram.bind();
sMatrix.setToIdentity();
shaderProgram.setUniformValue("mvpMatrix", sMatrix);
shpFill->Render(&shaderProgram);
shaderProgram.release();
}
void GlWidget::RenderShapes()
{
QMatrix4x4 sMatrix;
glClearColor(0.1f, 0.5f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, 256,256);
shaderProgram.bind();
sMatrix.setToIdentity();
shaderProgram.setUniformValue("mvpMatrix", sMatrix);
shpFill->Render(&shaderProgram);
shaderProgram.release();
}
To copy to clipboard, switch view to plain text mode
RenderLightingCube:
void FillShape::RenderLightingCube(QGLShaderProgram* lightingShaderProgram, GLuint cubeTexture)
{
lightingShaderProgram
->setUniformValue
("ambientColor",
QColor(32,
32,
32));
lightingShaderProgram
->setUniformValue
("diffuseColor",
QColor(128,
128,
128));
lightingShaderProgram
->setUniformValue
("specularColor",
QColor(255,
255,
255));
lightingShaderProgram->setUniformValue("ambientReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("diffuseReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("specularReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("shininess", (GLfloat) 100.0);
lightingShaderProgram->setUniformValue("texture", 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cubeTexture);
glActiveTexture(0);
lightingShaderProgram->setAttributeArray("vertex", cubeVertices.constData());
lightingShaderProgram->enableAttributeArray("vertex");
lightingShaderProgram->setAttributeArray("normal", cubeNormals.constData());
lightingShaderProgram->enableAttributeArray("normal");
lightingShaderProgram->setAttributeArray("textureCoordinate", cubeTextureCoordinates.constData());
lightingShaderProgram->enableAttributeArray("textureCoordinate");
glDrawArrays(GL_TRIANGLES, 0, cubeVertices.size());
lightingShaderProgram->disableAttributeArray("vertex");
lightingShaderProgram->disableAttributeArray("normal");
lightingShaderProgram->disableAttributeArray("textureCoordinate");
lightingShaderProgram->release();
}
void FillShape::RenderLightingCube(QGLShaderProgram* lightingShaderProgram, GLuint cubeTexture)
{
lightingShaderProgram->setUniformValue("ambientColor", QColor(32, 32, 32));
lightingShaderProgram->setUniformValue("diffuseColor", QColor(128, 128, 128));
lightingShaderProgram->setUniformValue("specularColor", QColor(255, 255, 255));
lightingShaderProgram->setUniformValue("ambientReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("diffuseReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("specularReflection", (GLfloat) 1.0);
lightingShaderProgram->setUniformValue("shininess", (GLfloat) 100.0);
lightingShaderProgram->setUniformValue("texture", 0);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cubeTexture);
glActiveTexture(0);
lightingShaderProgram->setAttributeArray("vertex", cubeVertices.constData());
lightingShaderProgram->enableAttributeArray("vertex");
lightingShaderProgram->setAttributeArray("normal", cubeNormals.constData());
lightingShaderProgram->enableAttributeArray("normal");
lightingShaderProgram->setAttributeArray("textureCoordinate", cubeTextureCoordinates.constData());
lightingShaderProgram->enableAttributeArray("textureCoordinate");
glDrawArrays(GL_TRIANGLES, 0, cubeVertices.size());
lightingShaderProgram->disableAttributeArray("vertex");
lightingShaderProgram->disableAttributeArray("normal");
lightingShaderProgram->disableAttributeArray("textureCoordinate");
lightingShaderProgram->release();
}
To copy to clipboard, switch view to plain text mode
Bookmarks