-void GLViewer_ViewFrame::onViewDump()
-{
- GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget();
- int width, height;
- width = aWidget->width();
- height = aWidget->height();
-
- int imageSize = width*height*3;
- unsigned char* imageBits = NULL;
-
- int reserve_bytes = width % 4; //32 bits platform
- imageSize = (width+reserve_bytes)*height*3;
- imageBits = new unsigned char[imageSize];
-
-
-#ifdef WNT
-
- int num;
- HBITMAP hBmp;
- HDC hdc_old, hdc;
- HGLRC hglrc_old, hglrc;
-
- BITMAPINFO bi;
-
- hglrc_old = wglGetCurrentContext();
- hdc_old = wglGetCurrentDC();
-
- hdc = CreateCompatibleDC( hdc_old );
- if( !hdc )
- {
- cout << "Can't create compatible DC. Last Error Code: " << GetLastError() << endl;
- return;
- }
-
- int sizeBmi = Standard_Integer( sizeof(BITMAPINFO) + sizeof(RGBQUAD)*3 );
- PBITMAPINFO pBmi = (PBITMAPINFO)( new char[sizeBmi] );
- ZeroMemory( pBmi, sizeBmi );
-
- pBmi->bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); //sizeBmi
- pBmi->bmiHeader.biWidth = width;
- pBmi->bmiHeader.biHeight = height;
- pBmi->bmiHeader.biPlanes = 1;
- pBmi->bmiHeader.biBitCount = 24;
- pBmi->bmiHeader.biCompression = BI_RGB;
-
- LPVOID ppvBits;
- hBmp = CreateDIBSection ( hdc, pBmi, DIB_RGB_COLORS, &ppvBits, NULL, 0 );
- SelectObject ( hdc, hBmp );
- delete[] pBmi;
-
- PIXELFORMATDESCRIPTOR pfd;
- ZeroMemory( &pfd, sizeof( PIXELFORMATDESCRIPTOR ) );
- pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR );
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 32;
- pfd.iLayerType = PFD_MAIN_PLANE;
-
- int iPf = ChoosePixelFormat( hdc, &pfd);
- if( iPf == 0 )
- {
- if ( !DescribePixelFormat ( hdc, iPf, sizeof(PIXELFORMATDESCRIPTOR), &pfd ) )
- {
- cout << "Can't describe Pixel Format. Last Error Code: " << GetLastError() << endl;
- }
- }
- if ( !SetPixelFormat(hdc, iPf, &pfd) )
- {
- cout << "Can't set Pixel Format. Last Error Code: " << GetLastError() << endl;
- }
-
- hglrc = wglCreateContext( hdc );
- if( !hglrc )
- {
- cout << "Can't create new GL Context. Last Error Code: " << GetLastError() << endl;
- return;
- }
- if( !wglMakeCurrent( hdc, hglrc) )
- {
- cout << "Can't make current new context!" << endl;
- return;
- }
-
- glViewport( 0, 0, width, height );
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- GLfloat w_c = width / 2., h_c = height / 2.;
-
- gluOrtho2D( -w_c, w_c, -h_c, h_c );
-
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
-
- //set background
- QColor aColor = ((GLViewer_ViewPort2d*)myVP)->backgroundColor();
- glClearColor( ( GLfloat )aColor.red() / 255,
- ( GLfloat )aColor.green() / 255,
- ( GLfloat )aColor.blue() / 255,
- 1.0 );
-
- aWidget->exportRepaint();
-
- memset(&bi, 0, sizeof(BITMAPINFOHEADER));
- bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bi.bmiHeader.biPlanes = 1;
- bi.bmiHeader.biBitCount = 24;
- bi.bmiHeader.biHeight = -height;
- bi.bmiHeader.biWidth = width;
- bi.bmiHeader.biCompression = BI_RGB;
-
- num = GetDIBits(hdc, hBmp, 0, height, imageBits, &bi, DIB_RGB_COLORS);
-
- wglMakeCurrent( hdc_old, hglrc_old );
- wglDeleteContext( hglrc );
-
-
-#else //XWindows
-#endif
-
- unsigned int* aPix = NULL;
- QImage anImage( width, height, 32 );
- for( int i = 0; i < height; i++ )
- {
- memset( anImage.scanLine( i ), 0, sizeof(unsigned int)*width );
- unsigned char* pos;
- for( int j = 0; j < width; j++ )
- {
- pos = imageBits + i*width*3 + j*3 + reserve_bytes*i;
- aPix = (unsigned int*)anImage.scanLine(i)+j;
- *aPix = qRgb( *pos, *(pos+1), *(pos+2) );
- }
- }
-
- delete [] imageBits;
-
- QString aFilter( "*.bmp\n*.png" );
-
- QFileDialog aFileDlg( QDir::current().absPath(), aFilter, this );
- aFileDlg.setCaption( tr( "DUMP_VIEW_SAVE_FILE_DLG_CAPTION" ) );
- aFileDlg.setMode( QFileDialog::AnyFile );
-
- if( !aFileDlg.exec() )
- return;
-
- QString aFileName = aFileDlg.selectedFile();
- QString aFileExt = aFileDlg.selectedFilter();