Jump to content
  • Advertisement
Sign in to follow this  
deadstar

[Qt] Trying to get QGraphicsView and OpenGL to play nice

This topic is 3718 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I've been tearing my hair out over the past view days getting Qt to render some OpenGL inside a QGraphicsView widget. The documentation claims the following:
Quote:
To render using OpenGL, simply call setViewport(new QGLWidget). QGraphicsView takes ownership of the viewport widget.
I'm absracting QGraphicsScene and reimplementing QGraphicsScene::drawForeground() in which to call my OpenGL stuff. For the past two days all I've been getting is a white window. Here is the relevant parts of the code: Header:
class Qt_OGLScene : public QGraphicsScene
{
	Q_OBJECT

	public:
		Qt_OGLScene (QWidget* parent = 0);
		~Qt_OGLScene ();

	protected:
		void drawForeground( QPainter* painter, const QRectF & rect );
};


Source:
void Qt_OGLScene::drawForeground( QPainter* painter, const QRectF & rect )
{
	glClear (GL_COLOR_BUFFER_BIT);
	glColor3f (1.0, 1.0, 1.0);
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
	
	glBegin(GL_POLYGON);
		glVertex3f (0.25, 0.25, 0.0);
		glVertex3f (0.75, 0.25, 0.0);
		glVertex3f (0.75, 0.75, 0.0);
		glVertex3f (0.25, 0.75, 0.0);
	glEnd();
	
	glFlush();
}


Main window setup:
Qt_OGLScene GLScene;

Qt_MainWindow::Qt_MainWindow(QWidget *parent)
{
    setupUi(this);

    Preview->setViewport(new QGLWidget);
    Preview->setScene(&GLScene);
}


I've been reading countless articles and browsing example code, and I can't get it to function. Thanks in advance for any help. EDIT: Forgot to mention, 'Preview' is the QGraphicsView widget, set up in the Qt4 Designer.

Share this post


Link to post
Share on other sites
Advertisement
Forget it, I found the problem just after posting. Typical.

My OpenGL 'test' code wasn't valid... can't believe I was so dumb.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!