{
public:
w(200), h(200)
{}
{
painter->drawRect(boundingRect());
painter->beginNativePainting();
glViewport(20, 20, w, h); /* Reset The Current Viewport And Perspective Transformation */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f , 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
painter->endNativePainting();
}
}
private:
int w, h;
};
class MyItem : public QGraphicsItem
{
public:
MyItem( QGraphicsItem * parent = 0 ) : QGraphicsItem(parent),
w(200), h(200)
{}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->drawRect(boundingRect());
painter->beginNativePainting();
glViewport(20, 20, w, h); /* Reset The Current Viewport And Perspective Transformation */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)w / (GLfloat)h, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f , 0.0f, -6.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
painter->endNativePainting();
}
QRectF boundingRect () const{
return QRectF(20,20,w,h);
}
private:
int w, h;
};
To copy to clipboard, switch view to plain text mode
Bookmarks