Changeset 1008 for trunk/source/visualization/OpenGL
- Timestamp:
- Apr 21, 2009, 10:30:53 AM (17 years ago)
- Location:
- trunk/source/visualization/OpenGL
- Files:
-
- 4 edited
-
include/G4OpenGLSceneHandler.hh (modified) (1 diff)
-
include/G4OpenGLXViewer.hh (modified) (3 diffs)
-
src/G4OpenGLViewer.cc (modified) (1 diff)
-
src/G4OpenGLXViewer.cc (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenGL/include/G4OpenGLSceneHandler.hh
r915 r1008 41 41 42 42 #include "G4VSceneHandler.hh" 43 #include "G4OpenGLBitMapStore.hh" ;43 #include "G4OpenGLBitMapStore.hh" 44 44 #include <GL/gl.h> 45 45 #include <GL/glu.h> -
trunk/source/visualization/OpenGL/include/G4OpenGLXViewer.hh
r977 r1008 57 57 void SetView (); 58 58 void ShowView (); 59 void printEPS();60 59 61 60 protected: … … 69 68 70 69 //////////////////////////////Pixmap (screen dump) production functions///// 71 GLXContext create_GL_print_context (XVisualInfo*& pvi);72 70 73 71 XWindowAttributes xwa; … … 98 96 char charViewName [100]; 99 97 100 bool grabPixelsX (unsigned int width, unsigned int height,GLenum format, GLubyte* buffer);101 int generateEPSX (const char* filnam,int inColour, unsigned int width,unsigned int height);102 103 98 104 99 private: -
trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
r980 r1008 489 489 #endif 490 490 if (fVectoredPs) { 491 #ifdef G4DEBUG_VIS_OGL492 printf("G4OpenGLViewer::printEPS Vectored\n");493 #endif494 491 res = printVectoredEPS(); 495 492 } else { 496 #ifdef G4DEBUG_VIS_OGL 497 printf("G4OpenGLViewer::printEPS NON Vectored\n"); 498 #endif 499 500 G4OpenGLXViewer* pOGLXViewer = dynamic_cast<G4OpenGLXViewer*>(this); 501 // if (pOGLXViewer) { 502 // res = printNonVectoredEPS(); 503 // pOGLXViewer->printEPS(); 504 // fPrintFilename = "G4OpenGLViewer_Print.eps"; 505 // } else { 506 res = printNonVectoredEPS(); 507 // } 493 res = printNonVectoredEPS(); 508 494 } 509 495 if (res == false) { -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc
r980 r1008 423 423 } 424 424 } 425 426 void G4OpenGLXViewer::printEPS() { 427 428 #ifdef G4DEBUG_VIS_OGL 429 printf("G4OpenGLXViewer::print \n"); 425 426 430 427 #endif 431 432 //using namespace std;433 //cout << "print_col_callback requested with file name: " << fPrintFilename << G4endl;434 435 if (fVectoredPs) {436 #ifdef G4DEBUG_VIS_OGL437 printf("G4OpenGLXViewer::print Vectored\n");438 #endif439 G4OpenGLViewer::printEPS();440 } else {441 #ifdef G4DEBUG_VIS_OGL442 printf("G4OpenGLXViewer::print non Vectored\n");443 #endif444 G4OpenGLViewer::printEPS();445 return;446 447 448 449 std::string fileTst = "G4OpenGL_XPixmapTestWithoutPixmap.eps";450 generateEPSX (fileTst.c_str(),451 fPrintColour,452 fWinSize_x, fWinSize_y);453 454 455 456 457 458 459 // G4StateManager* stateManager = G4StateManager::GetStateManager();460 // G4ApplicationState oldState = stateManager->GetCurrentState();461 // stateManager->SetNewState(G4State_Idle);462 463 // printEPS ();464 465 // stateManager->SetNewState(oldState);466 467 // // fPrintFilename = fPrintFilename+"-Gl2ps.ps";468 // return;469 470 // save context before471 XVisualInfo* tmp_vi = vi;472 GLXDrawable tmp_win = win;473 tmp_cx = cx;474 475 XVisualInfo* pvi;476 GLXContext pcx = create_GL_print_context(pvi);477 478 if (!pcx) {479 G4cout << "Unable to create print context." << G4endl;480 return;481 }482 483 #ifdef G4DEBUG_VIS_OGL484 printf("G4OpenGLXViewer::print Create pixmap Size :%d %d --- %d %d %d\n",fWinSize_x, fWinSize_y,vi,win,cx);485 #endif486 cx=pcx;487 488 Pixmap pmap = XCreatePixmap (dpy,489 XRootWindow (dpy, pvi->screen),490 fWinSize_x, fWinSize_y,491 pvi->depth);492 493 494 if (!pmap) {495 G4cout << "Unable to create pixmap." << G4endl;496 return;497 }498 499 500 GLXPixmap glxpmap = glXCreateGLXPixmap (dpy,501 pvi,502 pmap);503 504 if (!glxpmap) {505 G4cout << "Unable to create glx pixmap." << G4endl;506 return;507 }508 509 510 win=glxpmap;511 512 // int winX=fWinSize_x;513 // int winY=fWinSize_y;514 515 //#define CHECK_MULTIPLE_PRINT 1516 #ifdef CHECK_MULTIPLE_PRINT517 for (int tstX = 3000-2;tstX <=3000+2;tstX++) {518 for (int tstY = 3000-2;tstY <=3000+2;tstY++) {519 fWinSize_y = tstY;520 fWinSize_x = tstX;521 std::string file = "G4OpenGL_XPixmap";522 file += tstX;523 file +="x";524 file +=tstY;525 file +=".eps";526 #else527 std::string file = fPrintFilename.c_str();528 #endif529 530 // clear the buffers and window.531 SetView();532 ClearView ();533 534 #ifdef G4DEBUG_VIS_OGL535 printf("G4OpenGLXViewer::print Call DrawView \n");536 #endif537 538 539 540 // Need to force redraw for SXm mode541 NeedKernelVisit ();542 543 // Need to change state to IDLE544 G4StateManager* stateManager = G4StateManager::GetStateManager();545 G4ApplicationState oldState = stateManager->GetCurrentState();546 stateManager->SetNewState(G4State_Idle);547 548 549 550 DrawView (); // Will make current glX551 552 // Restore state553 stateManager->SetNewState(oldState);554 555 556 557 558 generateEPSX (file.c_str(),559 fPrintColour,560 fWinSize_x, fWinSize_y);561 562 #ifdef CHECK_MULTIPLE_PRINT563 }564 }565 fWinSize_y = winY;566 fWinSize_x = winX;567 #endif568 vi = tmp_vi;569 win = tmp_win;570 cx = tmp_cx;571 572 glXMakeCurrent (dpy, win, cx);573 // XVisualInfo* pvi = glXChooseVisual (dpy,574 // XDefaultScreen (dpy),575 // snglBuf_RGBA);576 577 // if (!pvi) {578 // pvi = glXChooseVisual (dpy,579 // XDefaultScreen (dpy),580 // dblBuf_RGBA);581 // }582 583 #ifdef G4DEBUG_VIS_OGL584 printf("G4OpenGLXViewer::print Restored %d %d %d\n",vi,win,cx);585 #endif586 // printf("Error 1:%d 2:%d\n",er1,er2);587 588 589 // Free print context590 XFreePixmap(dpy,pmap);591 glXDestroyContext(dpy,pcx);592 glXDestroyGLXPixmap(dpy,glxpmap);593 594 // Restore view in display context595 SetView();596 597 }598 599 }600 601 602 GLXContext G4OpenGLXViewer::create_GL_print_context(XVisualInfo*& pvi) {603 604 pvi = glXChooseVisual (dpy,605 XDefaultScreen (dpy),606 snglBuf_RGBA);607 608 if (!pvi) {609 pvi = glXChooseVisual (dpy,610 XDefaultScreen (dpy),611 dblBuf_RGBA);612 }613 614 // GLXFBConfig *fbc;615 // XVisualInfo *vi;616 // Colormap cmap;617 // XSetWindowAttributes swa;618 // Window win;619 // GLXContext cx;620 // GLXWindow gwin;621 // XEvent event;622 // int nelements;623 624 // /* Find a FBConfig that uses RGBA. Note that no attribute list is */625 // /* needed since GLX_RGBA_BIT is a default attribute. */626 // fbc = glXChooseFBConfig(dpy,XRootWindow (dpy, pvi->screen), 0, &nelements);627 // vi = glXGetVisualFromFBConfig(dpy, fbc[0]);628 629 // /* Create a GLX context using the first FBConfig in the list. */630 // return glXCreateNewContext(dpy, fbc[0], GLX_RGBA_TYPE, 0, GL_FALSE);631 632 633 634 return glXCreateContext (dpy,635 pvi,636 0,637 False);638 }639 640 641 bool G4OpenGLXViewer::grabPixelsX (unsigned int width, unsigned int height,GLenum format,GLubyte* buffer) {642 #ifdef G4DEBUG_VIS_OGL643 GLint viewport[4];644 glGetIntegerv(GL_VIEWPORT, viewport);645 printf("G4OpenGLXViewer::grabPixelsX %d %d viewport %d %d %d %d\n",width,height,viewport[0],viewport[1],viewport[2],viewport[3]);646 #endif647 648 GLint swapbytes, lsbfirst, rowlength;649 GLint skiprows, skippixels, alignment;650 651 unsigned int lineSize = 0;652 if (format == GL_RGB){653 lineSize = width*3;654 } else {655 lineSize = width*1;656 }657 658 GLubyte* lineBuffer = new GLubyte[lineSize];659 if (lineBuffer == NULL)660 return false;661 for (unsigned int y = 0; y<lineSize; y++) {662 lineBuffer[y] = 0;663 }664 665 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);666 glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);667 glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);668 669 glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);670 glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);671 glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);672 673 glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);674 glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);675 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);676 677 glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);678 glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);679 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);680 681 // FIXME L.Garnier 25 03 2009682 // Try to read at first a block of width by height683 // But on mac osX 10.5.6 on some window size their is684 // some stranges effects:685 // Pixels should came 3 values by 3 values but on border686 // it seems that with some window size there is a lack of687 // 1 or 2 values. For example a gray level picture like688 // (1,1,1) (2,2,2) (3,3,3)689 // (4,4,4) (5,5,5) (6,6,6)690 // (7,7,7) (8,8,8) (9,9,9)691 // appear as (with all buffer values init to 999) :692 // (1,1,1) (2,2,2) (3,3,3)693 // (999,999,4) (4,4,5) (5,5,6)694 // (6,6,999) (999,999,7) (7,7,8)695 // STRANGE EFFECT....696 697 // Then we read line by line...and NO problem !698 699 700 glReadBuffer(GL_FRONT);701 for (unsigned int i=0;i<height;i++) {702 glReadPixels (0, i, (GLsizei)width, 1, format, GL_UNSIGNED_BYTE, (GLvoid*) lineBuffer);703 glXWaitGL (); //Wait for effects of all previous OpenGL commands to704 // printf("\n%d ",i);705 for (unsigned int j=0;j<lineSize;j++) {706 buffer[j+i*lineSize] = lineBuffer[j];707 // printf("%d ",buffer[j]);708 }709 }710 // //be propagated before progressing.711 #ifdef G4DEBUG_VIS_OGL712 printf("G4OpenGLXViewer::GrabPixelX flush\n");713 #endif714 glFlush ();715 716 delete [] lineBuffer;717 718 glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);719 glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);720 glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength);721 722 glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows);723 glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels);724 glPixelStorei (GL_UNPACK_ALIGNMENT, alignment);725 726 727 return true;728 }729 730 int G4OpenGLXViewer::generateEPSX (const char* filnam,731 int inColour,732 unsigned int width,733 unsigned int height) {734 735 FILE* fp;736 GLubyte* pixels;737 GLubyte* curpix;738 int components;739 740 GLenum format;741 int size;742 743 if (inColour) {744 format = GL_RGB;745 size = width*height*3;746 } else {747 format = GL_LUMINANCE;748 size = width*height*1;749 }750 751 pixels = new GLubyte[size];752 if (pixels == NULL)753 return NULL;754 for (int y = 0; y<size; y++) {755 pixels[y] = 0;756 }757 758 759 #ifdef G4DEBUG_VIS_OGL760 printf("G4OpenGLXViewer::generateEPSX\n");761 #endif762 763 764 if (!grabPixelsX (width, height,format,pixels)) {765 return 1;766 }767 #ifdef G4DEBUG_VIS_OGL768 printf("--\n--\n--\n");769 #endif770 771 if (inColour) {772 components = 3;773 } else {774 components = 1;775 }776 777 fp = fopen (filnam, "w");778 if (fp == NULL) {779 return 2;780 }781 782 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n");783 fprintf (fp, "%%%%Title: %s\n", filnam);784 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n");785 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height);786 fprintf (fp, "%%%%EndComments\n");787 fprintf (fp, "gsave\n");788 fprintf (fp, "/bwproc {\n");789 fprintf (fp, " rgbproc\n");790 fprintf (fp, " dup length 3 idiv string 0 3 0 \n");791 fprintf (fp, " 5 -1 roll {\n");792 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n");793 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n");794 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n");795 fprintf (fp, " { 2 1 roll } ifelse\n");796 fprintf (fp, " }forall\n");797 fprintf (fp, " pop pop pop\n");798 fprintf (fp, "} def\n");799 fprintf (fp, "systemdict /colorimage known not {\n");800 fprintf (fp, " /colorimage {\n");801 fprintf (fp, " pop\n");802 fprintf (fp, " pop\n");803 fprintf (fp, " /rgbproc exch def\n");804 fprintf (fp, " { bwproc } image\n");805 fprintf (fp, " } def\n");806 fprintf (fp, "} if\n");807 fprintf (fp, "/picstr %d string def\n", width * components);808 fprintf (fp, "%d %d scale\n", width, height);809 fprintf (fp, "%d %d %d\n", width, height, 8);810 fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height);811 fprintf (fp, "{currentfile picstr readhexstring pop}\n");812 fprintf (fp, "false %d\n", components);813 fprintf (fp, "colorimage\n");814 815 curpix = (GLubyte*) pixels;816 unsigned int pos = 0;817 for (unsigned int i = width*height*components; i>0; i--) {818 fprintf (fp, "%02hx ", *(curpix++));819 if (++pos >= width) {820 // if (++pos >= 32) {821 fprintf (fp, "\n");822 pos = 0;823 }824 }825 if (pos)826 fprintf (fp, "\n");827 828 fprintf (fp, "grestore\n");829 fprintf (fp, "showpage\n");830 delete pixels;831 fclose (fp);832 833 #ifdef G4DEBUG_VIS_OGL834 printf("G4OpenGLXViewer::generateEPSX END\n");835 #endif836 837 return 0;838 }839 840 841 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
