diro
6th September 2011, 08:38
I created a object inherited from QGraphicsItem and reimplement the paint() function.
Inside the paint() function, I draw something by QPainter and call painter->beginNativePainting() to draw some elements with native openGL command.
It all works well, but when I rotate the object( object->rotate(45)), only the elements drawn by QPainter is rotated, the elements drawn by openGL command doesn't work.
It seems the QPainter use the shader to do those transformation(rotate), how can I apply the shader to my openGL elements?
Sample Code:
class MyItem:public QGraphicsItem
{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawText(0, 0, "123");
painter->fillRect(0, 0, 128, 128, Qt::green);
painter->beginNativePainting();
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 64, 64);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glEnd();
painter->endNativePainting();
}
QRectF boundingRect(void) const
{
return QRectF(0, 0, 100, 100);
}
};
Inside the paint() function, I draw something by QPainter and call painter->beginNativePainting() to draw some elements with native openGL command.
It all works well, but when I rotate the object( object->rotate(45)), only the elements drawn by QPainter is rotated, the elements drawn by openGL command doesn't work.
It seems the QPainter use the shader to do those transformation(rotate), how can I apply the shader to my openGL elements?
Sample Code:
class MyItem:public QGraphicsItem
{
public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawText(0, 0, "123");
painter->fillRect(0, 0, 128, 128, Qt::green);
painter->beginNativePainting();
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 64, 64);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
glEnd();
painter->endNativePainting();
}
QRectF boundingRect(void) const
{
return QRectF(0, 0, 100, 100);
}
};