Changeset 945 for trunk/source/visualization/OpenGL
- Timestamp:
- Mar 16, 2009, 6:36:09 PM (16 years ago)
- Location:
- trunk/source/visualization/OpenGL
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenGL/History
r942 r945 20 20 History file for visualization/OpenGL 21 21 ------------------------------------- 22 23 16th March 2009, Laurent Garnier 24 - G4OpenGLViewer : Add a check on max viewport dimensions when setting size. 22 25 23 26 4rd March 2009, Laurent Garnier -
trunk/source/visualization/OpenGL/include/G4OpenGLXViewer.hh
r915 r945 80 80 Colormap cmap; 81 81 XSetWindowAttributes swa; 82 GLXDrawable win;82 GLXDrawable fGLXWin; 83 83 GLXContext cx; 84 84 XEvent event; … … 98 98 char charViewName [100]; 99 99 100 GLubyte* grabPixelsX (int inColor, unsigned int width, unsigned int height); 101 int generateEPSX (const char* filnam,int inColour, unsigned int width,unsigned int height); 102 103 100 104 private: 101 105 G4OpenGLXViewer (const G4OpenGLXViewer&); -
trunk/source/visualization/OpenGL/src/G4OpenGLImmediateXViewer.cc
r915 r945 86 86 87 87 //Make sure current viewer is attached and clean... 88 glXMakeCurrent (dpy, win, cx);88 glXMakeCurrent (dpy, fGLXWin, cx); 89 89 90 90 if(style!=G4ViewParameters::hlr && -
trunk/source/visualization/OpenGL/src/G4OpenGLImmediateXmViewer.cc
r915 r945 92 92 93 93 //Make sure current viewer is attached and clean... 94 glXMakeCurrent (dpy, win, cx);94 glXMakeCurrent (dpy, fGLXWin, cx); 95 95 96 96 if(style!=G4ViewParameters::hlr && -
trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r941 r945 32 32 // functionality for OpenGL in GEANT4 33 33 // 34 // 27/06/2003 : G.Barrand : implementation (at last !).35 34 36 35 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER -
trunk/source/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc
r942 r945 222 222 if (fLastPolymarkers.size() > 0 ) { 223 223 224 // Loop new po lyto check224 // Loop new point to check 225 225 for (unsigned int b=0; b< polymarker.size();b++) { 226 printf("check %d/%d\n",b,polymarker.size());226 // printf("check %d/%d\n",b,polymarker.size()); 227 227 res= false; 228 229 // Look for stored point list 228 230 for (unsigned int a=0; a< fLastPolymarkers.size() ;a++) { 229 printf("against vect %d/%d\n",a,fLastPolymarker.size());231 // printf("against vect %d/%d\n",a,fLastPolymarker.size()); 230 232 std::vector < G4Polymarker > storedPoly = fLastPolymarkers[a]; 231 233 int size= storedPoly.size()-1; 232 for (unsigned int aPoly=0; aPoly< storedPoly[a].size() ;aPoly++) { 233 printf("against poly %d/%d\n",aPoly,storedPoly.size()); 234 235 // Look for point 236 for (int aPoly=0; aPoly< size ;aPoly++) { 237 // printf("against poly %d/%d\n",aPoly,storedPoly.size()); 234 238 if (( storedPoly[size-aPoly].GetPosition().x() == polymarker[b].x()) && 235 239 ( storedPoly[size-aPoly].GetPosition().y() == polymarker[b].y()) && … … 238 242 res= true; 239 243 nbDoublons++; 240 printf("G4OpenGLStoredSceneHandler::AddPrimitive PT %d/%d ALREADY FOUND TOT:%d. OLD pos %d/%d in %d PolyMarkerList STILL %d Marker in list. Point is %f %f %f\n",b,polymarker.size(), nbDoublons, aPoly,storedPoly[a].size(),a ,reste,polymarker[b].x(),polymarker[b].y(),polymarker[b].z());244 // printf("G4OpenGLStoredSceneHandler::AddPrimitive PT %d/%d ALREADY FOUND TOT:%d. OLD pos %d/%d in %d PolyMarkerList STILL %d Marker in list. Point is %f %f %f\n",b,polymarker.size(), nbDoublons, aPoly,size,a ,reste,polymarker[b].x(),polymarker[b].y(),polymarker[b].z()); 241 245 } 242 246 } -
trunk/source/visualization/OpenGL/src/G4OpenGLStoredViewer.cc
r911 r945 125 125 126 126 void G4OpenGLStoredViewer::DrawDisplayLists () { 127 #ifdef G4DEBUG_VIS_OGL 128 printf("G4OpenGLStoredViewer::DrawDisplayLists \n"); 129 #endif 127 130 128 131 const G4Planes& cutaways = fVP.GetCutawayPlanes(); … … 131 134 size_t nPasses = cutawayUnion? cutaways.size(): 1; 132 135 for (size_t i = 0; i < nPasses; ++i) { 136 #ifdef G4DEBUG_VIS_OGL 137 printf("G4OpenGLStoredViewer::DrawDisplayLists cutaway %d/%d\n",i,nPasses); 138 #endif 133 139 134 140 if (cutawayUnion) { … … 146 152 147 153 for (size_t i = 0; i < fG4OpenGLStoredSceneHandler.fTOList.size(); ++i) { 154 #ifdef G4DEBUG_VIS_OGL 155 printf("+"); 156 #endif 148 157 G4OpenGLStoredSceneHandler::TO& to = 149 158 fG4OpenGLStoredSceneHandler.fTOList[i]; -
trunk/source/visualization/OpenGL/src/G4OpenGLStoredXViewer.cc
r911 r945 78 78 79 79 //Make sure current viewer is attached and clean... 80 glXMakeCurrent (dpy, win, cx);80 glXMakeCurrent (dpy, fGLXWin, cx); 81 81 82 82 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); … … 127 127 GLint renderMode; 128 128 glGetIntegerv(GL_RENDER_MODE, &renderMode); 129 if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);129 if (renderMode == GL_RENDER) glXSwapBuffers (dpy, fGLXWin); 130 130 } 131 131 -
trunk/source/visualization/OpenGL/src/G4OpenGLStoredXmViewer.cc
r940 r945 87 87 88 88 //Make sure current viewer is attached and clean... 89 glXMakeCurrent (dpy, win, cx);89 glXMakeCurrent (dpy, fGLXWin, cx); 90 90 91 91 G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); … … 141 141 GLint renderMode; 142 142 glGetIntegerv(GL_RENDER_MODE, &renderMode); 143 if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);143 if (renderMode == GL_RENDER) glXSwapBuffers (dpy, fGLXWin); 144 144 } 145 145 -
trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
r942 r945 131 131 /** 132 132 * Set the viewport of the scene 133 * MAXIMUM SIZE is : 134 * GLint dims[2]; 135 * glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); 133 136 */ 134 137 void G4OpenGLViewer::ResizeGLView() 135 138 { 139 // Check size 140 GLint dims[2]; 141 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims); 142 if (fWinSize_x > (unsigned)dims[0]) { 143 G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[0] << G4endl; 144 fWinSize_x = dims[0]; 145 } 146 if (fWinSize_y > (unsigned)dims[1]) { 147 G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<dims[0] <<" is resize to "<< dims[1] << G4endl; 148 fWinSize_y = dims[1]; 149 } 136 150 int side = fWinSize_x; 137 151 if (fWinSize_y < fWinSize_x) side = fWinSize_y; … … 560 574 if (!fGL2PSAction) return false; 561 575 576 562 577 fGL2PSAction->setFileName(fPrintFilename.c_str()); 563 578 // try to resize … … 567 582 fWinSize_x = width; 568 583 fWinSize_y = height; 584 569 585 ResizeGLView(); 570 586 if (fGL2PSAction->enableFileWriting()) { 587 588 // FIXME : How to get the point size.... ? 589 fGL2PSAction->setLineWidth(1); 590 // FIXME : How to get the line width.... ? 591 fGL2PSAction->setPointSize(30); 592 571 593 DrawView (); 572 594 fGL2PSAction->disableFileWriting(); -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc
r942 r945 91 91 92 92 void G4OpenGLXViewer::SetView () { 93 glXMakeCurrent (dpy, win, cx);93 glXMakeCurrent (dpy, fGLXWin, cx); 94 94 G4OpenGLViewer::SetView (); 95 95 } … … 258 258 class_hints -> res_class = NewString("G4OpenGL"); 259 259 260 win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin,260 fGLXWin = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin, 261 261 y_origin, fWinSize_x, fWinSize_y, 0, vi -> depth, 262 262 InputOutput, vi -> visual, … … 265 265 &swa); 266 266 267 XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0,267 XSetWMProperties (dpy, fGLXWin, &windowName, &iconName, 0, 0, 268 268 size_hints, wm_hints, class_hints); 269 269 270 270 // request X to Draw window on screen. 271 XMapWindow (dpy, win);271 XMapWindow (dpy, fGLXWin); 272 272 273 273 // Wait for window to appear (wait for an "expose" event). 274 XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win);274 XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) fGLXWin); 275 275 276 276 // connect the context to a window 277 Bool success = glXMakeCurrent (dpy, win, cx);277 Bool success = glXMakeCurrent (dpy, fGLXWin, cx); 278 278 if (!success) { 279 279 fViewId = -1; // This flags an error. … … 404 404 glXMakeCurrent (dpy, None, NULL); 405 405 glXDestroyContext (dpy, cx); 406 if ( win) XDestroyWindow (dpy, win); // ...if already deleted in406 if (fGLXWin) XDestroyWindow (dpy, fGLXWin); // ...if already deleted in 407 407 // sub-class G4OpenGLXmViewer. 408 408 XFlush (dpy); … … 415 415 //cout << "print_col_callback requested with file name: " << fPrintFilename << G4endl; 416 416 417 if (fVectoredPs) { 417 418 #ifdef G4DEBUG_VIS_OGL 418 printf("G4OpenGLXViewer::print\n");419 printf("G4OpenGLXViewer::print Vectored\n"); 419 420 #endif 420 if (fVectoredPs) {421 421 printEPS(); 422 422 } else { 423 #ifdef G4DEBUG_VIS_OGL 424 printf("G4OpenGLXViewer::print non Vectored\n"); 425 #endif 423 426 // printEPS (); 424 427 // return; … … 446 449 447 450 GLXDrawable tmp_win; 448 tmp_win=win; 449 win=glxpmap; 450 451 tmp_win=fGLXWin; 452 fGLXWin=glxpmap; 453 454 // This won't work because fGLXWin is not known in G4OpenGLViewer... 455 451 456 glXMakeCurrent (dpy, 452 win,457 fGLXWin, 453 458 cx); 454 459 460 glViewport (0, 0, fWinSize_x, fWinSize_y); 461 455 462 ClearView (); 456 463 SetView (); 457 464 DrawView (); 458 465 459 printEPS (); 460 461 win=tmp_win; 466 std::string file = "G4OpenGL_XPixmap.eps"; 467 generateEPSX (file.c_str(), 468 fPrintColour, 469 fWinSize_x, fWinSize_y); 470 471 fGLXWin=tmp_win; 462 472 cx=tmp_cx; 463 473 464 474 glXMakeCurrent (dpy, 465 win,475 fGLXWin, 466 476 cx); 467 477 … … 489 499 } 490 500 501 502 GLubyte* G4OpenGLXViewer::grabPixelsX (int inColor, unsigned int width, unsigned int height) { 503 504 GLubyte* buffer; 505 GLint swapbytes, lsbfirst, rowlength; 506 GLint skiprows, skippixels, alignment; 507 GLenum format; 508 int size; 509 510 if (inColor) { 511 format = GL_RGB; 512 size = width*height*3; 513 } else { 514 format = GL_LUMINANCE; 515 size = width*height*1; 516 } 517 518 buffer = new GLubyte[size]; 519 if (buffer == NULL) 520 return NULL; 521 522 glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes); 523 glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst); 524 glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength); 525 526 glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows); 527 glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels); 528 glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment); 529 530 glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); 531 glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); 532 glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); 533 534 glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); 535 glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); 536 glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 537 538 glReadPixels (0, 0, (GLsizei)width, (GLsizei)height, format, GL_UNSIGNED_BYTE, (GLvoid*) buffer); 539 540 glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes); 541 glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst); 542 glPixelStorei (GL_UNPACK_ROW_LENGTH, rowlength); 543 544 glPixelStorei (GL_UNPACK_SKIP_ROWS, skiprows); 545 glPixelStorei (GL_UNPACK_SKIP_PIXELS, skippixels); 546 glPixelStorei (GL_UNPACK_ALIGNMENT, alignment); 547 548 return buffer; 549 } 550 551 int G4OpenGLXViewer::generateEPSX (const char* filnam, 552 int inColour, 553 unsigned int width, 554 unsigned int height) { 555 556 FILE* fp; 557 GLubyte* pixels; 558 GLubyte* curpix; 559 int components, pos, i; 560 561 pixels = grabPixelsX (inColour, width, height); 562 563 if (pixels == NULL) 564 return 1; 565 if (inColour) { 566 components = 3; 567 } else { 568 components = 1; 569 } 570 571 fp = fopen (filnam, "w"); 572 if (fp == NULL) { 573 return 2; 574 } 575 576 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); 577 fprintf (fp, "%%%%Title: %s\n", filnam); 578 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); 579 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", width, height); 580 fprintf (fp, "%%%%EndComments\n"); 581 fprintf (fp, "gsave\n"); 582 fprintf (fp, "/bwproc {\n"); 583 fprintf (fp, " rgbproc\n"); 584 fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); 585 fprintf (fp, " 5 -1 roll {\n"); 586 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); 587 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); 588 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); 589 fprintf (fp, " { 2 1 roll } ifelse\n"); 590 fprintf (fp, " }forall\n"); 591 fprintf (fp, " pop pop pop\n"); 592 fprintf (fp, "} def\n"); 593 fprintf (fp, "systemdict /colorimage known not {\n"); 594 fprintf (fp, " /colorimage {\n"); 595 fprintf (fp, " pop\n"); 596 fprintf (fp, " pop\n"); 597 fprintf (fp, " /rgbproc exch def\n"); 598 fprintf (fp, " { bwproc } image\n"); 599 fprintf (fp, " } def\n"); 600 fprintf (fp, "} if\n"); 601 fprintf (fp, "/picstr %d string def\n", width * components); 602 fprintf (fp, "%d %d scale\n", width, height); 603 fprintf (fp, "%d %d %d\n", width, height, 8); 604 fprintf (fp, "[%d 0 0 %d 0 0]\n", width, height); 605 fprintf (fp, "{currentfile picstr readhexstring pop}\n"); 606 fprintf (fp, "false %d\n", components); 607 fprintf (fp, "colorimage\n"); 608 609 curpix = (GLubyte*) pixels; 610 pos = 0; 611 for (i = width*height*components; i>0; i--) { 612 fprintf (fp, "%02hx ", *(curpix++)); 613 if (++pos >= 32) { 614 fprintf (fp, "\n"); 615 pos = 0; 616 } 617 } 618 if (pos) 619 fprintf (fp, "\n"); 620 621 fprintf (fp, "grestore\n"); 622 fprintf (fp, "showpage\n"); 623 delete pixels; 624 fclose (fp); 625 return 0; 626 } 627 628 491 629 #endif -
trunk/source/visualization/OpenGL/src/G4OpenGLXmViewer.cc
r915 r945 635 635 // can bind the OpenGL rendering context to the window. 636 636 637 win = XtWindow (glxarea);638 639 glXMakeCurrent (dpy, win, cx);637 fGLXWin = XtWindow (glxarea); 638 639 glXMakeCurrent (dpy, fGLXWin, cx); 640 640 641 641 // This should be add AFTER glXMakeCurrent done because it will fire a resizeCallback … … 684 684 { 685 685 XtDestroyWidget (shell); 686 win = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class686 fGLXWin = 0; // ...to avoid XDestroyWindow in G4OpenGLXViewer base class 687 687 // because XtDestroyWidget has already destroyed it. 688 688 G4Xt::getInstance () ->RemoveShell (shell);
Note: See TracChangeset
for help on using the changeset viewer.