如果一个普通的widget,不继承QGLWidget,而是自己设定qt的opengl环境,并在其上绘制,应该如何做呢?
我用的是qt3.3.8,这种想法是否可行。初学者跪请高人指点

Orz。
以下是一些代码,我的想法是在paintEvent中实现opengl的代码。
class TestWidget :public QWidget
{
public:
TestWidget(QWidget *parent=0,const char *name=0);
~TestWidget();
protected:
void paintEvent(QPaintEvent *);
void initGL();
void freeGL();
void initContext(QPaintDevice* pDevice);
protected:
QGLContext* m_pContext;
QGLContext* gpContext;
QPixmap pixmap;
};
//类实现*****************************************************************************************
TestWidget::TestWidget(QWidget *parent, const char *name):QWidget(parent, name, WNoAutoErase)
{
m_pContext=NULL;
gpContext=NULL;
initContext(&pixmap);
initGL();
}
TestWidget::~TestWidget()
{
freeGL();
}
void TestWidget::paintEvent(QPaintEvent * event)
{
QRect rect=event->rect();
QSize newSize = rect.size().expandedTo(pixmap.size());
pixmap.resize(newSize);
pixmap.fill(this, rect.topLeft());
m_pContext->makeCurrent();
glClear( GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-5, 0.0, -10.0);
glBegin(GL_TRIANGLES);
glVertex3f( 0.0, 1.0, 0.0 );
glVertex3f( -1.0, -1.0, 0.0 );
glVertex3f( 1.0, -1.0, 0.0 );
glEnd();
glFlush();
bitBlt(this, event->rect().topLeft(), &pixmap);
}
void TestWidget::freeGL()
{
//m_pContext->makeCurrent();
if(m_pContext)
delete m_pContext;
m_pContext = NULL;
}
void TestWidget::initGL()
{
//m_pContext->makeCurrent();
glShadeModel( GL_SMOOTH );
glClearColor( 0.0, 0.0, 0.0, 0.5 );
glClear(GL_COLOR_BUFFER_BIT);
glClearDepth( 1.0 );
glEnable( GL_DEPTH_TEST );
glDepthFunc( GL_LEQUAL );
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void TestWidget::initContext(QPaintDevice* pDevice)
{
if(!pDevice)
QApplication::exit(3);
if(m_pContext)
{
delete m_pContext;
m_pContext = NULL;
}
m_pContext = new QGLContext(QGLFormat::defaultFormat(),pDevice);
if(!(m_pContext->create()))
{
QApplication::exit(1);
}
if(!(m_pContext->isValid()))
{
QApplication::exit(2);
}
}
还有就是这个context到底怎么切换回qpainter,这样我是否能在qt3.38中,一个widget同时使用qpainter和qopengl绘制场景,使得qpainter 2维
界面绘制的长处得以发挥呢?