Ignore:
Timestamp:
Mar 24, 2009, 2:44:16 PM (15 years ago)
Author:
garnier
Message:

Creection de bug sur glViewport avec les divisions par 2

Location:
trunk/source/visualization/OpenGL
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/visualization/OpenGL/History

    r945 r949  
    2020History file for visualization/OpenGL
    2121-------------------------------------
     22
     2324th March 2009, Laurent Garnier
     24 - G4OpenGLViewer : Add a fix and resizing when X/Y size was even (lack of precision
     25   in a /2)
    2226
    232716th March 2009, Laurent Garnier
  • trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc

    r948 r949  
    138138void G4OpenGLViewer::ResizeGLView()
    139139{
    140   printf("G4OpenGLViewer::ResizeGLView\n");
     140  printf("G4OpenGLViewer::ResizeGLView %d %d\n",fWinSize_x,fWinSize_y);
    141141  // Check size
    142142  GLint dims[2];
     
    150150    fWinSize_y = dims[1];
    151151  }
    152   int side = fWinSize_x;
     152  GLsizei side = fWinSize_x;
    153153  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); 
    155176}
    156177
  • trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc

    r948 r949  
    459459
    460460#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);
    462462#endif
    463463    cx=pcx;
     
    473473      return;
    474474    }
     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
    475490    GLXPixmap glxpmap = glXCreateGLXPixmap (dpy,
    476491                                            pvi,
     
    481496      return;
    482497    }
     498
     499
    483500    GLXDrawable tmp_win;
    484501    tmp_win=fGLXWin;
    485502    fGLXWin=glxpmap;
    486503   
    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);
    493511   
    494512    //    InitializeGLView ();
    495513   
    496514    // clear the buffers and window.
     515    SetView();
    497516    ClearView ();
    498     SetView();
    499     //    FinishView ();
    500517
    501518#ifdef G4DEBUG_VIS_OGL
     
    518535
    519536    // Restore state
    520      stateManager->SetNewState(oldState); 
     537    stateManager->SetNewState(oldState); 
    521538
    522539
     
    535552                    cx);
    536553    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   
    541564  }
    542565
     
    586609GLubyte* G4OpenGLXViewer::grabPixelsX (int inColor, unsigned int width, unsigned int height) {
    587610#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]);
    589614#endif
    590615         
    591   GLubyte* buffer;
     616  //  GLubyte* buffer;
     617  GLint* bufferI;
    592618  GLint swapbytes, lsbfirst, rowlength;
    593619  GLint skiprows, skippixels, alignment;
     
    603629  }
    604630       
     631  unsigned char *buffer = new unsigned char [ size] ;
    605632  buffer = new GLubyte[size];
     633  bufferI = new int[size];
    606634  if (buffer == NULL)
    607635    return NULL;
    608        
     636  for (int y = 0; y<size; y++) {
     637    buffer[y] = 0;
     638  }
    609639  glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
    610640  glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
     
    615645  glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
    616646       
    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);
    624654       
    625655  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);
    626657       
    627658  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
     
    630661
    631662//   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 
    642677//   printf("-----------\n-----------\n-----------\n-----------\n-----------\n");
    643 
     678 
    644679  glPixelStorei (GL_UNPACK_SWAP_BYTES, swapbytes);
    645680  glPixelStorei (GL_UNPACK_LSB_FIRST, lsbfirst);
     
    665700       
    666701#ifdef G4DEBUG_VIS_OGL
    667     printf("G4OpenGLXViewer::generateEPSX\n");
    668 #endif
     702  printf("G4OpenGLXViewer::generateEPSX\n");
     703#endif
     704 
    669705
    670706  pixels = grabPixelsX (inColour, width, height);
     
    723759  for (i = width*height*components; i>0; i--) {
    724760    fprintf (fp, "%02hx ", *(curpix++));
    725     if (++pos >= 32) {
     761    if (++pos >= width) {
     762      //    if (++pos >= 32) {
    726763      fprintf (fp, "\n");
    727764      pos = 0;
Note: See TracChangeset for help on using the changeset viewer.