Changeset 950 for trunk/source/visualization/OpenGL
- Timestamp:
- Mar 25, 2009, 11:12:05 AM (15 years ago)
- Location:
- trunk/source/visualization/OpenGL
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenGL/History
r949 r950 1 $Id: History,v 1.1 29 2009/03/05 16:36:13lgarnier Exp $1 $Id: History,v 1.131 2009/03/24 13:50:07 lgarnier Exp $ 2 2 ------------------------------------------------------------------- 3 3 … … 24 24 - G4OpenGLViewer : Add a fix and resizing when X/Y size was even (lack of precision 25 25 in a /2) 26 27 18th March 2009 John Allison 28 - G4OpenGLViewerMessenger.cc: printMode and transparency are available 29 for all OGL windows (they were previously inadvertently hidden by 30 an OGLS requirement). 26 31 27 32 16th March 2009, Laurent Garnier -
trunk/source/visualization/OpenGL/include/G4OpenGLXViewer.hh
r946 r950 98 98 char charViewName [100]; 99 99 100 GLubyte* grabPixelsX (int inColor, unsigned int width, unsigned int height);100 bool grabPixelsX (unsigned int width, unsigned int height,GLenum format, GLubyte* buffer); 101 101 int generateEPSX (const char* filnam,int inColour, unsigned int width,unsigned int height); 102 102 -
trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
r949 r950 164 164 // SPECIAL CASE 165 165 if ((fWinSize_x - side)%2) { 166 fWinSize_x --; 166 // fWinSize_x --; 167 168 side = fWinSize_x; 169 if (fWinSize_y < fWinSize_x) side = fWinSize_y; 167 170 } 168 171 if ((fWinSize_y - side)%2) { 169 fWinSize_y --; 170 } 171 172 GLint width = (fWinSize_x - side) / 2; 173 GLint height = (fWinSize_y - side) / 2; 174 175 glViewport(width, height, side, side); 172 // fWinSize_y --; 173 174 side = fWinSize_x; 175 if (fWinSize_y < fWinSize_x) side = fWinSize_y; 176 } 177 178 GLint X = (fWinSize_x - side) / 2; 179 GLint Y = (fWinSize_y - side) / 2; 180 181 printf("G4OpenGLViewer::ResizeGLView X:%d Y:%d W:%d H:%d --side%d\n",(fWinSize_x - side) / 2,(fWinSize_y - side) / 2,fWinSize_x,fWinSize_y,side); 182 glViewport(X, Y, side, side); 183 // glViewport(0, 0, fWinSize_x,fWinSize_y); 184 185 176 186 } 177 187 -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc
r949 r950 511 511 512 512 // InitializeGLView (); 513 513 int winX=fWinSize_x; 514 int winY=fWinSize_y; 515 516 for (int tstX = winX-2;tstX <=winX+2;tstX++) { 517 for (int tstY = winY-2;tstY <=winY+2;tstY++) { 518 fWinSize_y = tstY; 519 fWinSize_x = tstX; 520 std::string file = "G4OpenGL_XPixmap"; 521 file += tstX; 522 file +="x"; 523 file +=tstY; 524 file +=".eps"; 525 514 526 // clear the buffers and window. 515 527 SetView(); … … 540 552 541 553 542 std::string file = "G4OpenGL_XPixmap.eps";543 554 generateEPSX (file.c_str(), 544 555 fPrintColour, 545 556 fWinSize_x, fWinSize_y); 546 557 558 } 559 } 547 560 fGLXWin=tmp_win; 548 561 cx=tmp_cx; … … 607 620 608 621 609 GLubyte* G4OpenGLXViewer::grabPixelsX (int inColor, unsigned int width, unsigned int height) {622 bool G4OpenGLXViewer::grabPixelsX (unsigned int width, unsigned int height,GLenum format,GLubyte* buffer) { 610 623 #ifdef G4DEBUG_VIS_OGL 611 624 GLint viewport[4]; … … 614 627 #endif 615 628 616 // GLubyte* buffer;617 GLint* bufferI;618 629 GLint swapbytes, lsbfirst, rowlength; 619 630 GLint skiprows, skippixels, alignment; 620 GLenum format; 621 int size; 622 623 if (inColor) { 624 format = GL_RGB; 625 size = width*height*3; 631 632 unsigned int lineSize = 0; 633 if (format == GL_RGB){ 634 lineSize = width*3; 626 635 } else { 627 format = GL_LUMINANCE; 628 size = width*height*1; 629 } 630 631 unsigned char *buffer = new unsigned char [ size] ; 632 buffer = new GLubyte[size]; 633 bufferI = new int[size]; 634 if (buffer == NULL) 635 return NULL; 636 for (int y = 0; y<size; y++) { 637 buffer[y] = 0; 638 } 636 lineSize = width*1; 637 } 638 639 GLubyte* lineBuffer = new GLubyte[lineSize]; 640 if (lineBuffer == NULL) 641 return false; 642 for (int y = 0; y<lineSize; y++) { 643 lineBuffer[y] = 0; 644 } 645 639 646 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes); 640 647 glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst); … … 645 652 glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment); 646 653 647 // glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); 648 // glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); 649 // glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); 650 651 // glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); 652 // glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); 653 // glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 654 655 glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer); 656 // glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_INT, bufferI); 657 658 glXWaitGL (); //Wait for effects of all previous OpenGL commands to 654 glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); 655 glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); 656 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); 657 658 glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); 659 glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); 660 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 661 662 // FIXME L.Garnier 25 03 2009 663 // Try to read at first a block of width by height 664 // But on mac osX 10.5.6 on some window size their is 665 // some stranges effects: 666 // Pixels should came 3 values by 3 values but on border 667 // it seems that with some window size there is a lack of 668 // 1 or 2 values. For example a gray level picture like 669 // (1,1,1) (2,2,2) (3,3,3) 670 // (4,4,4) (5,5,5) (6,6,6) 671 // (7,7,7) (8,8,8) (9,9,9) 672 // appear as (with all buffer values init to 999) : 673 // (1,1,1) (2,2,2) (3,3,3) 674 // (999,999,4) (4,4,5) (5,5,6) 675 // (6,6,999) (999,999,7) (7,7,8) 676 // STRANGE EFFECT.... 677 678 // Then we read line by line...and NO problem ! 679 680 681 for (int i=0;i<height;i++) { 682 glReadPixels (0, i, (GLsizei)width, 1, format, GL_UNSIGNED_BYTE, (GLvoid*) lineBuffer); 683 glXWaitGL (); //Wait for effects of all previous OpenGL commands to 684 // printf("\n%d ",i); 685 for (int j=0;j<lineSize;j++) { 686 buffer[j+i*lineSize] = lineBuffer[j]; 687 // printf("%d ",buffer[j]); 688 } 689 } 659 690 // //be propagated before progressing. 660 691 glFlush (); 661 692 662 // printf("-----------\n-----------\n-----------\n-----------\n-----------\n%d %d %d\n",width, height,size); 663 // char * pixels = new char [3 * width * height]; 664 // glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); 665 666 for (int y = 0; y<height*3; y++) { 667 printf("\n%d : ",y/3); 668 for (int x = 0; x<width*3; x++) { 669 printf("%d ",buffer[y*width+x]); 670 // if (buffer[y*width+x] == 0) 671 // printf(""); 672 // else if (buffer[y*width+x] == 255) 673 // printf("0"); 674 } 675 } 676 677 // printf("-----------\n-----------\n-----------\n-----------\n-----------\n"); 693 delete [] lineBuffer; 678 694 679 695 glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes); … … 686 702 687 703 688 return buffer;704 return true; 689 705 } 690 706 … … 698 714 GLubyte* curpix; 699 715 int components, pos, i; 716 717 GLenum format; 718 int size; 719 720 if (inColour) { 721 format = GL_RGB; 722 size = width*height*3; 723 } else { 724 format = GL_LUMINANCE; 725 size = width*height*1; 726 } 727 728 pixels = new GLubyte[size]; 729 if (pixels == NULL) 730 return NULL; 731 for (int y = 0; y<size; y++) { 732 pixels[y] = 0; 733 } 734 700 735 701 736 #ifdef G4DEBUG_VIS_OGL … … 704 739 705 740 706 pixels = grabPixelsX (inColour, width, height); 741 if (!grabPixelsX (width, height,format,pixels)) { 742 return 1; 743 } 707 744 #ifdef G4DEBUG_VIS_OGL 708 745 printf("--\n--\n--\n"); 709 746 #endif 710 747 711 if (pixels == NULL)712 return 1;713 748 if (inColour) { 714 749 components = 3; … … 772 807 delete pixels; 773 808 fclose (fp); 809 810 #ifdef G4DEBUG_VIS_OGL 811 printf("G4OpenGLXViewer::generateEPSX END\n"); 812 #endif 813 774 814 return 0; 775 815 }
Note: See TracChangeset
for help on using the changeset viewer.