PDA

View Full Version : Fragment shader with 2d



krzat
20th December 2010, 20:01
What should I do to make this simple shader work (everything should be blue I guess)?


class GLWidget : public QGLWidget {
public:
GLWidget(QWidget *parent = 0): QGLWidget(parent) {}
protected:
void initializeGL()
{
this->setFixedSize(200,200);
fbo = new QGLFramebufferObject(200, 200);
QPainter p(fbo);
p.fillRect(10,10,30,30,Qt::yellow);

QGLShaderProgram shader(this);
if(shader.addShaderFromSourceCode(QGLShader::Fragm ent,
"void main(void) {gl_FragColor = vec4(0, 0, 1, 1.0);}"))
qDebug("Shader prepared.");
shader.link();
shader.bind();
}
void paintEvent(QPaintEvent *event)
{
QPainter painter(this);
//painter.fillRect(0,0,200,100, Qt::gray); // line2
painter.fillRect(60,20,30,30, Qt::gray);
drawTexture(QPoint(10, 10), fbo->texture());

}
private:
QGLFramebufferObject *fbo;
};

stampede
20th December 2010, 21:37
QGLShaderProgram shader(this);
Try to create shader object on the heap:

QGLShaderProgram * shader = new QGlShaderProgram(this);
In your code "shader" goes out of scope, this probably unloads it from the rendering pipeline.