Click here to Skip to main content
15,867,568 members
Articles / Desktop Programming / MFC

Writing a Platform and GUI Toolkit Independent OpenGL Class

Rate me:
Please Sign up or sign in to vote.
4.92/5 (33 votes)
1 Nov 2010CPOL13 min read 96.2K   7.5K   88  
Article showing how to write OS and GUI toolkit portable OpenGL view class
#include "glframe.h"

#ifndef WIN32
#include <QX11Info>
#endif


GLFrame::GLFrame(QWidget *parent)
	: QWidget(parent)
{
	m_pGLView = new CGLView();
	if(m_pGLView)
	{
		setAttribute(Qt::WA_PaintOnScreen);
#ifdef WIN32
		m_pGLView->SetWindow((HWND)winId());
#else
		Display* pDisp = x11Info().display();
    	Window wnd = winId();
		m_pGLView->SetWindow(pDisp, wnd);
#endif
		m_pGLView->SetupGLContext(true);
		m_pGLView->Resize(width(), height());
	}
}

QPaintEngine * GLFrame::paintEngine () const
{
	return 0;
}

GLFrame::~GLFrame()
{
	if(m_pGLView)
	{
		delete m_pGLView;
	}
}

void GLFrame::paintEvent(QPaintEvent* /*event*/)
{
	if(m_pGLView)
	{
		m_pGLView->RenderScene();
	}
}

void GLFrame::resizeEvent(QResizeEvent* event)
{
	if(m_pGLView)
	{
		QSize size = event->size();
		m_pGLView->Resize(size.width(), size.height());
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions