Changeset 949 for trunk/source
- Timestamp:
- Mar 24, 2009, 2:44:16 PM (15 years ago)
- Location:
- trunk/source/visualization/OpenGL
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenGL/History
r945 r949 20 20 History file for visualization/OpenGL 21 21 ------------------------------------- 22 23 24th March 2009, Laurent Garnier 24 - G4OpenGLViewer : Add a fix and resizing when X/Y size was even (lack of precision 25 in a /2) 22 26 23 27 16th March 2009, Laurent Garnier -
trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
r948 r949 138 138 void G4OpenGLViewer::ResizeGLView() 139 139 { 140 printf("G4OpenGLViewer::ResizeGLView \n");140 printf("G4OpenGLViewer::ResizeGLView %d %d\n",fWinSize_x,fWinSize_y); 141 141 // Check size 142 142 GLint dims[2]; … … 150 150 fWinSize_y = dims[1]; 151 151 } 152 intside = fWinSize_x;152 GLsizei side = fWinSize_x; 153 153 if (fWinSize_y < fWinSize_x) side = fWinSize_y; 154 glViewport((fWinSize_x - side) / 2, (fWinSize_y - side) / 2, side, side); 154 155 // SPECIAL CASE if fWinSize_x is even (69 for example) 156 // Ex : X: 69 Y: 26 157 // side = 26 158 // width / 2 = 21,5 159 // height / 2 = 0 160 // Should be fixed to closed : 21 0 for ex 161 // Then size must by change to : 162 // X:68 Y: 26 163 164 // SPECIAL CASE 165 if ((fWinSize_x - side)%2) { 166 fWinSize_x --; 167 } 168 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); 155 176 } 156 177 -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc
r948 r949 459 459 460 460 #ifdef G4DEBUG_VIS_OGL 461 printf("G4OpenGLXViewer::print Create pixmap old context:%d new context %d old winGL:%d \n",cx,pcx,fGLXWin);461 printf("G4OpenGLXViewer::print Create pixmap old context:%d new context %d old winGL:%d Size :%d %d\n",cx,pcx,fGLXWin,fWinSize_x, fWinSize_y); 462 462 #endif 463 463 cx=pcx; … … 473 473 return; 474 474 } 475 476 Drawable root; 477 int x, y; 478 unsigned int rw, rh,bw,rd; 479 480 481 XGetGeometry(dpy, pmap, &root, &x, &y, &rw, &rh, &bw, &rd); 482 #ifdef G4DEBUG_VIS_OGL 483 printf("G4OpenGLXViewer::print after creation Size :%d %d %d %d rh:%D bw:%d rd:%d\n",x,y,rw,rh, bw, rd); 484 #endif 485 // Seems to be OK 486 487 488 489 475 490 GLXPixmap glxpmap = glXCreateGLXPixmap (dpy, 476 491 pvi, … … 481 496 return; 482 497 } 498 499 483 500 GLXDrawable tmp_win; 484 501 tmp_win=fGLXWin; 485 502 fGLXWin=glxpmap; 486 503 487 // 488 bool er1 = glXMakeCurrent (dpy, 489 fGLXWin, // pixmap win Id 490 cx); // pixmap context Id 491 492 glViewport (0, 0, fWinSize_x, fWinSize_y); 504 // Should be remove : Already done by SetView 505 // bool er1 = glXMakeCurrent (dpy, 506 // fGLXWin, // pixmap win Id 507 // cx); // pixmap context Id 508 509 // should be remove because already done by SetView() 510 // glViewport (0, 0, fWinSize_x, fWinSize_y); 493 511 494 512 // InitializeGLView (); 495 513 496 514 // clear the buffers and window. 515 SetView(); 497 516 ClearView (); 498 SetView();499 // FinishView ();500 517 501 518 #ifdef G4DEBUG_VIS_OGL … … 518 535 519 536 // Restore state 520 537 stateManager->SetNewState(oldState); 521 538 522 539 … … 535 552 cx); 536 553 printf("G4OpenGLXViewer::print Restored context:%d old winGL:%d \n",cx,fGLXWin); 537 printf("Error 1:%d 2:%d\n",er1,er2); 538 539 // glXDestroyContext(pcx); 540 // glXDestroyGLXPixmap(glpixmap) 554 // printf("Error 1:%d 2:%d\n",er1,er2); 555 556 // Free print context 557 XFreePixmap(dpy,pmap); 558 glXDestroyContext(dpy,pcx); 559 glXDestroyGLXPixmap(dpy,glxpmap); 560 561 // Restore view in display context 562 SetView(); 563 541 564 } 542 565 … … 586 609 GLubyte* G4OpenGLXViewer::grabPixelsX (int inColor, unsigned int width, unsigned int height) { 587 610 #ifdef G4DEBUG_VIS_OGL 588 printf("G4OpenGLXViewer::grabPixelsX\n"); 611 GLint viewport[4]; 612 glGetIntegerv(GL_VIEWPORT, viewport); 613 printf("G4OpenGLXViewer::grabPixelsX %d %d viewport %d %d %d %d\n",width,height,viewport[0],viewport[1],viewport[2],viewport[3]); 589 614 #endif 590 615 591 GLubyte* buffer; 616 // GLubyte* buffer; 617 GLint* bufferI; 592 618 GLint swapbytes, lsbfirst, rowlength; 593 619 GLint skiprows, skippixels, alignment; … … 603 629 } 604 630 631 unsigned char *buffer = new unsigned char [ size] ; 605 632 buffer = new GLubyte[size]; 633 bufferI = new int[size]; 606 634 if (buffer == NULL) 607 635 return NULL; 608 636 for (int y = 0; y<size; y++) { 637 buffer[y] = 0; 638 } 609 639 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes); 610 640 glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst); … … 615 645 glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment); 616 646 617 glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);618 glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);619 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);620 621 glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);622 glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);623 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);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); 624 654 625 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); 626 657 627 658 glXWaitGL (); //Wait for effects of all previous OpenGL commands to … … 630 661 631 662 // printf("-----------\n-----------\n-----------\n-----------\n-----------\n%d %d %d\n",width, height,size); 632 // char * pixels = new char [3 * width * height]; 633 // glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, GL_DEPTH_COMPONENT, GL_FLOAT, pixels); 634 635 // for (int i = 0; i<size; i++) { 636 // if (pixels[i] != 0) 637 // printf("%d ",pixels[i]); 638 // else 639 // printf(" "); 640 // } 641 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 642 677 // printf("-----------\n-----------\n-----------\n-----------\n-----------\n"); 643 678 644 679 glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes); 645 680 glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst); … … 665 700 666 701 #ifdef G4DEBUG_VIS_OGL 667 printf("G4OpenGLXViewer::generateEPSX\n"); 668 #endif 702 printf("G4OpenGLXViewer::generateEPSX\n"); 703 #endif 704 669 705 670 706 pixels = grabPixelsX (inColour, width, height); … … 723 759 for (i = width*height*components; i>0; i--) { 724 760 fprintf (fp, "%02hx ", *(curpix++)); 725 if (++pos >= 32) { 761 if (++pos >= width) { 762 // if (++pos >= 32) { 726 763 fprintf (fp, "\n"); 727 764 pos = 0;
Note: See TracChangeset
for help on using the changeset viewer.