| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.16 2007/06/25 16:38:13 $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-08-02-patch-01 $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
|
|---|
| 32 | // G4OpenGLImmediateViewer.
|
|---|
| 33 |
|
|---|
| 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
|
|---|
| 35 |
|
|---|
| 36 | #include "G4OpenGLImmediateQtViewer.hh"
|
|---|
| 37 |
|
|---|
| 38 | #include "G4ios.hh"
|
|---|
| 39 |
|
|---|
| 40 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| 41 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| 42 | const G4String& name):
|
|---|
| 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 46 | G4OpenGLImmediateViewer (sceneHandler),
|
|---|
| 47 | QGLWidget() // FIXME : gerer le pb du parent !
|
|---|
| 48 | {
|
|---|
| 49 |
|
|---|
| 50 | 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 |
|
|---|
| 62 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| 63 | printf("GLWidget::~GLWidget \n");
|
|---|
| 64 | makeCurrent();
|
|---|
| 65 | glDeleteLists(object, 1);
|
|---|
| 66 | printf("GLWidget::~GLWidget END\n");
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| 70 | printf("GLWidget::Initialise \n");
|
|---|
| 71 | printf("readyToPaint = false \n");
|
|---|
| 72 | readyToPaint = false;
|
|---|
| 73 | // printf("G4OpenGLImmediateQtViewer::Initialise () 1\n");
|
|---|
| 74 | // CreateGLQtContext ();
|
|---|
| 75 | printf("G4OpenGLImmediateQtViewer::Initialise () 2\n");
|
|---|
| 76 |
|
|---|
| 77 | CreateMainWindow (this);
|
|---|
| 78 | printf("G4OpenGLImmediateQtViewer::Initialise () 3\n");
|
|---|
| 79 |
|
|---|
| 80 | // CreateFontLists (); // FIXME Does nothing!
|
|---|
| 81 |
|
|---|
| 82 | printf("readyToPaint = true \n");
|
|---|
| 83 | readyToPaint = true;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void 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");
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 | void G4OpenGLImmediateQtViewer::DrawView () {
|
|---|
| 121 |
|
|---|
| 122 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| 123 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 124 | // back buffer for this OpenGLImmediate view.
|
|---|
| 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 ();
|
|---|
| 149 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| 150 |
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | void G4OpenGLImmediateQtViewer::DrawView2 () {
|
|---|
| 154 |
|
|---|
| 155 | printf("G4OpenGLImmediateQtViewer::DrawView2 %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| 156 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 157 | // back buffer for this OpenGLImmediate view.
|
|---|
| 158 | glDrawBuffer (GL_FRONT);
|
|---|
| 159 |
|
|---|
| 160 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 161 |
|
|---|
| 162 | //Make sure current viewer is attached and clean...
|
|---|
| 163 | //Qt version needed
|
|---|
| 164 | //glXMakeCurrent (dpy, win, cx);
|
|---|
| 165 | glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| 166 |
|
|---|
| 167 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 168 | haloing_enabled) {
|
|---|
| 169 |
|
|---|
| 170 | HaloingFirstPass ();
|
|---|
| 171 | NeedKernelVisit ();
|
|---|
| 172 | ProcessView ();
|
|---|
| 173 | glFlush ();
|
|---|
| 174 |
|
|---|
| 175 | HaloingSecondPass ();
|
|---|
| 176 |
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 180 | ProcessView ();
|
|---|
| 181 | FinishView ();
|
|---|
| 182 | printf("G4OpenGLImmediateQtViewer::DrawView2 %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| 183 |
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 188 | void G4OpenGLImmediateQtViewer::FinishView (
|
|---|
| 189 | )
|
|---|
| 190 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 191 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 192 | {
|
|---|
| 193 | printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| 194 | // // if(!fHDC) return;
|
|---|
| 195 |
|
|---|
| 196 | // glFlush ();
|
|---|
| 197 | printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 198 |
|
|---|
| 199 | // Empty the Windows message queue :
|
|---|
| 200 | // MSG event;
|
|---|
| 201 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
|
|---|
| 202 | // ::TranslateMessage(&event);
|
|---|
| 203 | // ::DispatchMessage (&event);
|
|---|
| 204 | // }
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 209 | int width
|
|---|
| 210 | ,int height)
|
|---|
| 211 | {
|
|---|
| 212 | printf("GLWidget::resizeGL\n");
|
|---|
| 213 | int side = qMin(width, height);
|
|---|
| 214 | glViewport((width - side) / 2, (height - side) / 2, side, side);
|
|---|
| 215 |
|
|---|
| 216 | glMatrixMode(GL_PROJECTION);
|
|---|
| 217 | glLoadIdentity();
|
|---|
| 218 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
|
|---|
| 219 | glMatrixMode(GL_MODELVIEW);
|
|---|
| 220 | printf("GLWidget::resizeGL END\n");
|
|---|
| 221 | // printf("G4OpenGLImmediateQtViewer::resizeGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
|
|---|
| 222 |
|
|---|
| 223 | // int side = qMin(width, height);
|
|---|
| 224 | // glViewport((width - side) / 2, (height - side) / 2, side, side);
|
|---|
| 225 | // glMatrixMode(GL_PROJECTION);
|
|---|
| 226 | // glLoadIdentity();
|
|---|
| 227 | // glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
|
|---|
| 228 | // glMatrixMode(GL_MODELVIEW);
|
|---|
| 229 |
|
|---|
| 230 | // printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 234 | {
|
|---|
| 235 | if (!readyToPaint)
|
|---|
| 236 | return;
|
|---|
| 237 | printf("GLWidget::paintGL\n");
|
|---|
| 238 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|---|
| 239 | glLoadIdentity();
|
|---|
| 240 | glTranslated(0.0, 0.0, -10.0);
|
|---|
| 241 | glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
|
|---|
| 242 | glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
|
|---|
| 243 | glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
|
|---|
| 244 | glCallList(object);
|
|---|
| 245 | printf("GLWidget::paintGL END\n");
|
|---|
| 246 | // printf("G4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
|
|---|
| 247 | // float b=3;
|
|---|
| 248 |
|
|---|
| 249 | // WinSize_x = (G4int) width();
|
|---|
| 250 | // WinSize_y = (G4int) height();
|
|---|
| 251 |
|
|---|
| 252 | // glViewport (0, 0, width(), height());
|
|---|
| 253 |
|
|---|
| 254 | SetView();
|
|---|
| 255 | // // printf("before ClearView\n");
|
|---|
| 256 | // // makeCurrent();
|
|---|
| 257 | // // for (int a=0;a<100000000;a++) {b = b/3.1456;}
|
|---|
| 258 | // printf(" ClearView\n");
|
|---|
| 259 | ClearView (); //ok, put the background correct
|
|---|
| 260 | // DrawView2();
|
|---|
| 261 | // // ShowView();
|
|---|
| 262 | // // printf("before ClearView\n");
|
|---|
| 263 | // // ClearView (); //ok, put the background correct
|
|---|
| 264 | // // FIXME
|
|---|
| 265 | FinishView();
|
|---|
| 266 | // // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|---|
| 267 | // // glLoadIdentity();
|
|---|
| 268 | // // glTranslated(0.0, 0.0, -10.0);
|
|---|
| 269 |
|
|---|
| 270 | // printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 | GLuint G4OpenGLImmediateQtViewer::makeObject()
|
|---|
| 277 | {
|
|---|
| 278 | GLuint list = glGenLists(1);
|
|---|
| 279 | glNewList(list, GL_COMPILE);
|
|---|
| 280 |
|
|---|
| 281 | glBegin(GL_QUADS);
|
|---|
| 282 |
|
|---|
| 283 | GLdouble x1 = +0.06;
|
|---|
| 284 | GLdouble y1 = -0.14;
|
|---|
| 285 | GLdouble x2 = +0.14;
|
|---|
| 286 | GLdouble y2 = -0.06;
|
|---|
| 287 | GLdouble x3 = +0.08;
|
|---|
| 288 | GLdouble y3 = +0.00;
|
|---|
| 289 | GLdouble x4 = +0.30;
|
|---|
| 290 | GLdouble y4 = +0.22;
|
|---|
| 291 |
|
|---|
| 292 | quad(x1, y1, x2, y2, y2, x2, y1, x1);
|
|---|
| 293 | quad(x3, y3, x4, y4, y4, x4, y3, x3);
|
|---|
| 294 |
|
|---|
| 295 | extrude(x1, y1, x2, y2);
|
|---|
| 296 | extrude(x2, y2, y2, x2);
|
|---|
| 297 | extrude(y2, x2, y1, x1);
|
|---|
| 298 | extrude(y1, x1, x1, y1);
|
|---|
| 299 | extrude(x3, y3, x4, y4);
|
|---|
| 300 | extrude(x4, y4, y4, x4);
|
|---|
| 301 | extrude(y4, x4, y3, x3);
|
|---|
| 302 |
|
|---|
| 303 | const double Pi = 3.14159265358979323846;
|
|---|
| 304 | const int NumSectors = 200;
|
|---|
| 305 |
|
|---|
| 306 | for (int i = 0; i < NumSectors; ++i) {
|
|---|
| 307 | double angle1 = (i * 2 * Pi) / NumSectors;
|
|---|
| 308 | GLdouble x5 = 0.30 * sin(angle1);
|
|---|
| 309 | GLdouble y5 = 0.30 * cos(angle1);
|
|---|
| 310 | GLdouble x6 = 0.20 * sin(angle1);
|
|---|
| 311 | GLdouble y6 = 0.20 * cos(angle1);
|
|---|
| 312 |
|
|---|
| 313 | double angle2 = ((i + 1) * 2 * Pi) / NumSectors;
|
|---|
| 314 | GLdouble x7 = 0.20 * sin(angle2);
|
|---|
| 315 | GLdouble y7 = 0.20 * cos(angle2);
|
|---|
| 316 | GLdouble x8 = 0.30 * sin(angle2);
|
|---|
| 317 | GLdouble y8 = 0.30 * cos(angle2);
|
|---|
| 318 |
|
|---|
| 319 | quad(x5, y5, x6, y6, x7, y7, x8, y8);
|
|---|
| 320 |
|
|---|
| 321 | extrude(x6, y6, x7, y7);
|
|---|
| 322 | extrude(x8, y8, x5, y5);
|
|---|
| 323 | }
|
|---|
| 324 |
|
|---|
| 325 | glEnd();
|
|---|
| 326 |
|
|---|
| 327 | glEndList();
|
|---|
| 328 | return list;
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | void G4OpenGLImmediateQtViewer::quad(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2,
|
|---|
| 332 | GLdouble x3, GLdouble y3, GLdouble x4, GLdouble y4)
|
|---|
| 333 | {
|
|---|
| 334 | qglColor(trolltechGreen);
|
|---|
| 335 |
|
|---|
| 336 | glVertex3d(x1, y1, -0.05);
|
|---|
| 337 | glVertex3d(x2, y2, -0.05);
|
|---|
| 338 | glVertex3d(x3, y3, -0.05);
|
|---|
| 339 | glVertex3d(x4, y4, -0.05);
|
|---|
| 340 |
|
|---|
| 341 | glVertex3d(x4, y4, +0.05);
|
|---|
| 342 | glVertex3d(x3, y3, +0.05);
|
|---|
| 343 | glVertex3d(x2, y2, +0.05);
|
|---|
| 344 | glVertex3d(x1, y1, +0.05);
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | void G4OpenGLImmediateQtViewer::extrude(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2)
|
|---|
| 348 | {
|
|---|
| 349 | qglColor(trolltechGreen.dark(250 + int(100 * x1)));
|
|---|
| 350 |
|
|---|
| 351 | glVertex3d(x1, y1, +0.05);
|
|---|
| 352 | glVertex3d(x2, y2, +0.05);
|
|---|
| 353 | glVertex3d(x2, y2, -0.05);
|
|---|
| 354 | glVertex3d(x1, y1, -0.05);
|
|---|
| 355 | }
|
|---|
| 356 |
|
|---|
| 357 | #endif
|
|---|