00001 #include "renderwindow.h"
00002
00048 RenderWindow::RenderWindow(QGLFormat glf, QWidget * parent, const char * name )
00049 : QGLWidget(glf, parent, name) {
00050 this->InitRenderWindow();
00051 }
00052
00053
00062 RenderWindow::RenderWindow( QWidget * parent, const char * name)
00063 : QGLWidget(parent, name) {
00064 this->InitRenderWindow();
00065 }
00066
00072 void RenderWindow::InitRenderWindow() {
00073 this->initNeeded = true;
00074 this->renderWindow = vtkRenderWindow::New();
00075 this->renderer = vtkRenderer::New();
00076 this->renderWindow->AddRenderer( this->renderer );
00077 this->light = vtkLight::New();
00078 this->renderer->AddLight( this->light );
00079
00080
00081 #ifdef QT_DOUBLEBUFFER
00082
00083 this->renderWindow->SetSwapBuffers(0);
00084 #else
00085
00086 this->setAutoBufferSwap( false );
00087 #endif
00088 }
00089
00093 RenderWindow::~RenderWindow() {
00094 this->renderer->Delete();
00095 this->renderWindow->Delete();
00096 }
00097
00101 vtkRenderer *RenderWindow::GetRenderer() {
00102 return this->renderer;
00103 }
00104
00108 vtkRenderWindow *RenderWindow::GetRenderWindow( ) {
00109 return this->renderWindow;
00110 }
00111
00115 void RenderWindow::initializeGL( ) {
00116 glClearColor(1.0, 1.0, 1.0, 1.0);
00117 glColor3f(1.0, 0.0, 0.0);
00118 }
00119
00123 void RenderWindow::resizeGL( int w, int h) {
00124 glMatrixMode( GL_PROJECTION );
00125 glLoadIdentity();
00126 gluOrtho2D( 0.0, w, 0.0, h );
00127 glMatrixMode( GL_MODELVIEW );
00128
00129 updateGL();
00130 }
00131
00135 void RenderWindow::paintGL( )
00136 {
00137
00138
00139
00140 if (this->initNeeded) {
00141 WId nId = winId();
00142 this->renderWindow->SetWindowId( (void*) nId );
00143 this->initNeeded = false;
00144 }
00145 else {
00146 this->renderWindow->Render();
00147 }
00148 }