MainWindow
::MainWindow( QWidget *parent
):{
GraphicsView *view = new GraphicsView;
view
->setViewport
( new QGLWidget( QGLFormat( QGL
::SampleBuffers | QGL
::AlphaChannel | QGL
::Rgba ) ) );
view
->setViewportUpdateMode
( QGraphicsView::FullViewportUpdate );
view->setScene( new OpenGLScene );
resize( 320, 240 );
setCentralWidget( view );
}
GraphicsView::GraphicsView()
{
}
{
if (scene())
scene
()->setSceneRect
( QRect( QPoint( 0,
0 ), e
->size
() ) );
}
OpenGLScene::OpenGLScene()
{
}
OpenGLScene::~OpenGLScene()
{
}
void OpenGLScene
::drawBackground( QPainter */*painter*/,
const QRectF &/*rect*/ ) {
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glViewport( 0, 0, int( width() ), int( height() ) );
//glOrtho( -width() / 2.0, width() / 2.0, -height() / 2.0, height() / 2.0, -1.0, 1000.0 );
glOrtho( 0.0, width(), height(), 0.0, -1.0, 1000.0 );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
// DRAW HERE
glPopMatrix();
glPopMatrix();
//QTimer::singleShot( 1, this, SLOT(update()) );
}
MainWindow::MainWindow( QWidget *parent ):
QMainWindow( parent )
{
GraphicsView *view = new GraphicsView;
view->setViewport( new QGLWidget( QGLFormat( QGL::SampleBuffers | QGL::AlphaChannel | QGL::Rgba ) ) );
view->setViewportUpdateMode( QGraphicsView::FullViewportUpdate );
view->setScene( new OpenGLScene );
resize( 320, 240 );
setCentralWidget( view );
}
GraphicsView::GraphicsView()
{
}
void GraphicsView::resizeEvent( QResizeEvent *e )
{
if (scene())
scene()->setSceneRect( QRect( QPoint( 0, 0 ), e->size() ) );
QGraphicsView::resizeEvent(e);
}
OpenGLScene::OpenGLScene()
{
}
OpenGLScene::~OpenGLScene()
{
}
void OpenGLScene::drawBackground( QPainter */*painter*/, const QRectF &/*rect*/ )
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glViewport( 0, 0, int( width() ), int( height() ) );
//glOrtho( -width() / 2.0, width() / 2.0, -height() / 2.0, height() / 2.0, -1.0, 1000.0 );
glOrtho( 0.0, width(), height(), 0.0, -1.0, 1000.0 );
glMatrixMode( GL_MODELVIEW );
glPushMatrix();
glLoadIdentity();
// DRAW HERE
glPopMatrix();
glPopMatrix();
//QTimer::singleShot( 1, this, SLOT(update()) );
}
To copy to clipboard, switch view to plain text mode
Bookmarks