Ignore:
Timestamp:
Jul 12, 2007, 5:32:59 PM (17 years ago)
Author:
garnier
Message:

r706@mac-90108: laurentgarnier | 2007-07-11 11:52:27 +0200
modif en mettant l exemple OpenGL a la place : CA MARCHE

Location:
trunk/geant4/visualization/OpenGL
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/include/G4OpenGLImmediateQtViewer.hh

    r543 r551  
    5252  G4OpenGLImmediateQtViewer (G4OpenGLImmediateSceneHandler& scene,
    5353                                const G4String& name = "");
     54  ~G4OpenGLImmediateQtViewer ();
    5455  void Initialise ();
    55   void InitialiseGL ();
     56  void initializeGL ();
    5657  void DrawView ();
    5758  void FinishView ();
     
    6061private :
    6162  int readyToPaint;
     63
     64
     65private:
     66     GLuint makeObject();
     67     void quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
     68               GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4);
     69     void extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
     70/*      void normalizeAngle(int *angle); */
     71
     72     GLuint object;
     73     int xRot;
     74     int yRot;
     75     int zRot;
     76     QPoint lastPos;
     77     QColor trolltechGreen;
     78     QColor trolltechPurple;
     79
    6280};
    6381
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateQtViewer.cc

    r550 r551  
    4949
    5050  if (fViewId < 0) return;  // In case error in base class instantiation.
     51   printf("GLWidget::GLWidget \n");
     52     object = 0;
     53     xRot = 0;
     54     yRot = 0;
     55     zRot = 0;
     56
     57     trolltechGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
     58     trolltechPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);
     59   printf("GLWidget::GLWidget END\n");
     60}
     61
     62G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
     63   printf("GLWidget::~GLWidget \n");
     64     makeCurrent();
     65     glDeleteLists(object, 1);
     66   printf("GLWidget::~GLWidget END\n");
    5167}
    5268
    5369void G4OpenGLImmediateQtViewer::Initialise() {
    54   printf("G4OpenGLImmediateQtViewer::Initialise () 1\n");
    55   CreateGLQtContext ();
     70   printf("GLWidget::Initialise \n");
     71   //  printf("readyToPaint = false \n");
     72  //  readyToPaint = false;
     73   //  printf("G4OpenGLImmediateQtViewer::Initialise () 1\n");
     74  //  CreateGLQtContext ();
    5675  printf("G4OpenGLImmediateQtViewer::Initialise () 2\n");
    5776
    5877  CreateMainWindow (this);
    5978  printf("G4OpenGLImmediateQtViewer::Initialise () 3\n");
    60   CreateFontLists ();
    61 }
    62 
    63 void G4OpenGLImmediateQtViewer::InitialiseGL () {
    64   printf("G4OpenGLImmediateQtViewer::InitialiseGL   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
    65   readyToPaint = false;
    66 
    67 // ensure a suitable window was found
    68 
    69   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 4\n");
    70   readyToPaint = true;
    71 
    72   InitializeGLView ();
    73 
    74   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 5\n");
    75 
    76   // clear the buffers and window.
    77   //  ClearView ();
    78   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 6\n");
    79   //  FinishView ();
    80   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 7\n");
    81 
    82   // If a double buffer context has been forced upon us, ignore the
    83   // back buffer for this OpenGLImmediate view.
    84   glDrawBuffer (GL_FRONT);
    85 
    86   glDepthFunc (GL_LEQUAL);
    87   glDepthMask (GL_TRUE);
    88   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 8\n");
    89 
    90   printf("G4OpenGLImmediateQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
     79
     80  //  CreateFontLists ();  // FIXME Does nothing!
     81
     82  printf("readyToPaint = true \n");
     83  //  readyToPaint = true;
     84}
     85
     86void G4OpenGLImmediateQtViewer::initializeGL () {
     87   printf("GLWidget::initializeGL \n");
     88     qglClearColor(trolltechPurple.dark());
     89     object = makeObject();
     90     glShadeModel(GL_FLAT);
     91     glEnable(GL_DEPTH_TEST);
     92     glEnable(GL_CULL_FACE);
     93   printf("GLWidget::initializeGL END\n");
     94
     95//   printf("G4OpenGLImmediateQtViewer::InitialiseGL   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
     96
     97// // ensure a suitable window was found
     98
     99
     100//   InitializeGLView ();
     101
     102//   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 1\n");
     103
     104//   // clear the buffers and window.
     105//   //  ClearView ();
     106//   printf("G4OpenGLImmediateQtViewer::InitialiseGL () 2\n");
     107//   //  FinishView ();
     108
     109//   // If a double buffer context has been forced upon us, ignore the
     110//   // back buffer for this OpenGLImmediate view.
     111//   glDrawBuffer (GL_FRONT);
     112
     113//   glDepthFunc (GL_LEQUAL);
     114//   glDepthMask (GL_TRUE);
     115
     116//   printf("G4OpenGLImmediateQtViewer::InitialiseGL  -------------------------------------------------------------------------------------\n");
    91117}
    92118
     
    97123  // If a double buffer context has been forced upon us, ignore the
    98124  // back buffer for this OpenGLImmediate view.
    99   glDrawBuffer (GL_FRONT);
    100 
    101   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
    102 
    103   //Make sure current viewer is attached and clean...
    104   //Qt version needed
    105   //glXMakeCurrent (dpy, win, cx);
    106   glViewport (0, 0, WinSize_x, WinSize_y);
    107 
    108   if(style!=G4ViewParameters::hlr &&
    109      haloing_enabled) {
    110 
    111     HaloingFirstPass ();
    112     NeedKernelVisit ();
    113     ProcessView ();
    114     glFlush ();
    115 
    116     HaloingSecondPass ();
    117 
    118   }
    119 
    120   NeedKernelVisit ();  // Always need to visit G4 kernel.
    121   ProcessView ();
    122   FinishView ();
     125//   glDrawBuffer (GL_FRONT);
     126
     127//   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
     128
     129//   //Make sure current viewer is attached and clean...
     130//   //Qt version needed
     131//   //glXMakeCurrent (dpy, win, cx);
     132//   glViewport (0, 0, WinSize_x, WinSize_y);
     133
     134//   if(style!=G4ViewParameters::hlr &&
     135//      haloing_enabled) {
     136
     137//     HaloingFirstPass ();
     138//     NeedKernelVisit ();
     139//     ProcessView ();
     140//     glFlush ();
     141
     142//     HaloingSecondPass ();
     143
     144//   }
     145
     146//   NeedKernelVisit ();  // Always need to visit G4 kernel.
     147//   ProcessView ();
     148//   FinishView ();
    123149  printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
    124150
     
    133159{
    134160  printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
    135   //    if(!fHDC) return;
    136 
    137   glFlush ();
     161//   //    if(!fHDC) return;
     162
     163//   glFlush ();
    138164  printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
    139165
     
    151177,int height)
    152178{
    153   printf("G4OpenGLImmediateQtViewer::resizeGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
    154   /*
    155   int side = qMin(width, height);
    156   glViewport((width - side) / 2, (height - side) / 2, side, side);
    157   glMatrixMode(GL_PROJECTION);
    158   glLoadIdentity();
    159   glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
    160   glMatrixMode(GL_MODELVIEW);
    161   */
    162   printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
     179   printf("GLWidget::resizeGL\n");
     180     int side = qMin(width, height);
     181     glViewport((width - side) / 2, (height - side) / 2, side, side);
     182
     183     glMatrixMode(GL_PROJECTION);
     184     glLoadIdentity();
     185     glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     186     glMatrixMode(GL_MODELVIEW);
     187   printf("GLWidget::resizeGL END\n");
     188//   printf("G4OpenGLImmediateQtViewer::resizeGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
     189 
     190//   int side = qMin(width, height);
     191//   glViewport((width - side) / 2, (height - side) / 2, side, side);
     192//   glMatrixMode(GL_PROJECTION);
     193//   glLoadIdentity();
     194//   glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
     195//   glMatrixMode(GL_MODELVIEW);
     196 
     197//   printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
    163198}
    164199
    165200void G4OpenGLImmediateQtViewer::paintGL()
    166201 {
    167   printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
    168   float b=3;
    169   if (!readyToPaint)
    170     return;
    171 
    172   //  WinSize_x = (G4int) width();
    173   //  WinSize_y = (G4int) height();
    174 
    175   //  glViewport (0, 0, width(), height());
    176 
    177   //  SetView();
    178   printf("before ClearView\n");
    179   //  makeCurrent();
    180   for (int a=0;a<100000000;a++) {b = b/3.1456;}
    181   printf("    ClearView\n");
    182   //  ClearView (); //ok, put the background correct
    183   //  DrawView();
    184   //  ShowView();
    185   //  printf("before ClearView\n");
    186   //  ClearView (); //ok, put the background correct
    187   printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    188   // FIXME
    189   //  FinishView();
    190   //  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    191   //  glLoadIdentity();
    192   //  glTranslated(0.0, 0.0, -10.0);
    193 
    194  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    195  glLoadIdentity();
    196  glTranslatef(-1.5f,0.0f,-6.0f);
    197  glBegin(GL_TRIANGLES);
    198  glVertex3f( 0.0f, 1.0f, 0.0f);
    199  glVertex3f(-1.0f,-1.0f, 0.0f);
    200  glVertex3f( 1.0f,-1.0f, 0.0f);
    201  glEnd();
    202  glTranslatef(3.0f,0.0f,0.0f);
    203  glBegin(GL_QUADS);
    204  glVertex3f(-1.0f, 1.0f, 0.0f);
    205  glVertex3f( 1.0f, 1.0f, 0.0f);
    206  glVertex3f( 1.0f,-1.0f, 0.0f);
    207  glVertex3f(-1.0f,-1.0f, 0.0f);
    208  glEnd();
     202   printf("GLWidget::paintGL\n");
     203     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     204     glLoadIdentity();
     205     glTranslated(0.0, 0.0, -10.0);
     206     glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
     207     glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
     208     glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
     209     glCallList(object);
     210   printf("GLWidget::paintGL END\n");
     211//   printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
     212//   float b=3;
     213//   if (!readyToPaint)
     214//     return;
     215
     216//   WinSize_x = (G4int) width();
     217//   WinSize_y = (G4int) height();
     218
     219//   glViewport (0, 0, width(), height());
     220
     221//   SetView();
     222//   //  printf("before ClearView\n");
     223//   //  makeCurrent();
     224//   //  for (int a=0;a<100000000;a++) {b = b/3.1456;}
     225//   printf("    ClearView\n");
     226//   ClearView (); //ok, put the background correct
     227//   //  DrawView();
     228//   //  ShowView();
     229//   //  printf("before ClearView\n");
     230//   //  ClearView (); //ok, put the background correct
     231//   // FIXME
     232//   //  FinishView();
     233//   //  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     234//   //  glLoadIdentity();
     235//   //  glTranslated(0.0, 0.0, -10.0);
     236
     237//   printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
    209238 }
     239
     240
     241
     242
     243 GLuint G4OpenGLImmediateQtViewer::makeObject()
     244 {
     245     GLuint list = glGenLists(1);
     246     glNewList(list, GL_COMPILE);
     247
     248     glBegin(GL_QUADS);
     249
     250     GLdouble x1 = +0.06;
     251     GLdouble y1 = -0.14;
     252     GLdouble x2 = +0.14;
     253     GLdouble y2 = -0.06;
     254     GLdouble x3 = +0.08;
     255     GLdouble y3 = +0.00;
     256     GLdouble x4 = +0.30;
     257     GLdouble y4 = +0.22;
     258
     259     quad(x1, y1, x2, y2, y2, x2, y1, x1);
     260     quad(x3, y3, x4, y4, y4, x4, y3, x3);
     261
     262     extrude(x1, y1, x2, y2);
     263     extrude(x2, y2, y2, x2);
     264     extrude(y2, x2, y1, x1);
     265     extrude(y1, x1, x1, y1);
     266     extrude(x3, y3, x4, y4);
     267     extrude(x4, y4, y4, x4);
     268     extrude(y4, x4, y3, x3);
     269
     270     const double Pi = 3.14159265358979323846;
     271     const int NumSectors = 200;
     272
     273     for (int i = 0; i < NumSectors; ++i) {
     274         double angle1 = (i * 2 * Pi) / NumSectors;
     275         GLdouble x5 = 0.30 * sin(angle1);
     276         GLdouble y5 = 0.30 * cos(angle1);
     277         GLdouble x6 = 0.20 * sin(angle1);
     278         GLdouble y6 = 0.20 * cos(angle1);
     279
     280         double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
     281         GLdouble x7 = 0.20 * sin(angle2);
     282         GLdouble y7 = 0.20 * cos(angle2);
     283         GLdouble x8 = 0.30 * sin(angle2);
     284         GLdouble y8 = 0.30 * cos(angle2);
     285
     286         quad(x5, y5, x6, y6, x7, y7, x8, y8);
     287
     288         extrude(x6, y6, x7, y7);
     289         extrude(x8, y8, x5, y5);
     290     }
     291
     292     glEnd();
     293
     294     glEndList();
     295     return list;
     296 }
     297
     298 void G4OpenGLImmediateQtViewer::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
     299                     GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
     300 {
     301     qglColor(trolltechGreen);
     302
     303     glVertex3d(x1, y1, -0.05);
     304     glVertex3d(x2, y2, -0.05);
     305     glVertex3d(x3, y3, -0.05);
     306     glVertex3d(x4, y4, -0.05);
     307
     308     glVertex3d(x4, y4, +0.05);
     309     glVertex3d(x3, y3, +0.05);
     310     glVertex3d(x2, y2, +0.05);
     311     glVertex3d(x1, y1, +0.05);
     312 }
     313
     314 void G4OpenGLImmediateQtViewer::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
     315 {
     316     qglColor(trolltechGreen.dark(250 + int(100 * x1)));
     317
     318     glVertex3d(x1, y1, +0.05);
     319     glVertex3d(x2, y2, +0.05);
     320     glVertex3d(x2, y2, -0.05);
     321     glVertex3d(x1, y1, -0.05);
     322 }
     323
    210324#endif
Note: See TracChangeset for help on using the changeset viewer.