source: trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc@ 531

Last change on this file since 531 was 529, checked in by garnier, 18 years ago

r658@mac-90108: laurentgarnier | 2007-06-25 12:02:16 +0200
import de visualisation

  • Property svn:mime-type set to text/cpp
File size: 6.6 KB
Line 
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: G4OpenGLImmediateSceneHandler.cc,v 1.24 2006/09/04 12:03:25 allison Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
29//
30//
31// Andrew Walkden 10th February 1997
32// OpenGL immediate scene - draws immediately to buffer
33// (saving space on server).
34
35#ifdef G4VIS_BUILD_OPENGL_DRIVER
36
37// Included here - problems with HP compiler if not before other includes?
38#include "G4NURBS.hh"
39
40// Here follows a special for Mesa, the OpenGL emulator. Does not affect
41// other OpenGL's, as far as I'm aware. John Allison 18/9/96.
42#define CENTERLINE_CLPP /* CenterLine C++ workaround: */
43// Also seems to be required for HP's CC and AIX xlC, at least.
44
45#include "G4OpenGLImmediateSceneHandler.hh"
46
47#include "G4OpenGLTransform3D.hh"
48#include "G4Polyline.hh"
49#include "G4Circle.hh"
50#include "G4Square.hh"
51
52G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler (G4VGraphicsSystem& system,
53 const G4String& name):
54G4OpenGLSceneHandler (system, fSceneIdCount++, name)
55{}
56
57G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler ()
58{}
59
60#include <iomanip>
61
62void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
63{
64 const G4Colour& c = GetColour (visible);
65 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
66}
67
68void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline)
69{
70 AddPrimitivePreamble(polyline);
71 G4OpenGLSceneHandler::AddPrimitive(polyline);
72}
73
74void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle)
75{
76 AddPrimitivePreamble(circle);
77 G4OpenGLSceneHandler::AddPrimitive(circle);
78}
79
80void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square)
81{
82 AddPrimitivePreamble(square);
83 G4OpenGLSceneHandler::AddPrimitive(square);
84}
85
86void G4OpenGLImmediateSceneHandler::BeginPrimitives
87(const G4Transform3D& objectTransformation) {
88 G4VSceneHandler::BeginPrimitives (objectTransformation);
89 glPushMatrix();
90 G4OpenGLTransform3D oglt (objectTransformation);
91
92 /*************************** Check matrix.
93 const GLdouble* m = oglt.GetGLMatrix ();
94 G4cout << "G4OpenGLTransform3D matrix:";
95 for (int i = 0; i < 16; i++) {
96 if ((i % 4) == 0) G4cout << '\n';
97 G4cout << std::setw (15) << m[i];
98 }
99 G4cout << G4endl;
100 *****************************************/
101
102 glMultMatrixd (oglt.GetGLMatrix ());
103}
104
105void G4OpenGLImmediateSceneHandler::EndPrimitives ()
106{
107 glPopMatrix();
108
109 // See all primitives immediately...
110 glFlush ();
111
112 G4VSceneHandler::EndPrimitives ();
113}
114
115void G4OpenGLImmediateSceneHandler::BeginPrimitives2D()
116{
117 G4VSceneHandler::BeginPrimitives2D();
118
119 // Push current 3D world matrices and load identity to define screen
120 // coordinates...
121 glMatrixMode (GL_PROJECTION);
122 glPushMatrix();
123 glLoadIdentity();
124 glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
125 glMatrixMode (GL_MODELVIEW);
126 glPushMatrix();
127 glLoadIdentity();
128}
129
130void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
131{
132 // Pop current 3D world matrices back again...
133 glMatrixMode (GL_PROJECTION);
134 glPopMatrix();
135 glMatrixMode (GL_MODELVIEW);
136 glPopMatrix();
137
138 // See all primitives immediately...
139 glFlush ();
140
141 G4VSceneHandler::EndPrimitives2D ();
142}
143
144void G4OpenGLImmediateSceneHandler::BeginModeling () {
145 G4VSceneHandler::BeginModeling();
146}
147
148void G4OpenGLImmediateSceneHandler::EndModeling () {
149 G4VSceneHandler::EndModeling ();
150}
151
152void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
153
154 G4VSceneHandler::ClearTransientStore ();
155
156 // Make sure screen corresponds to graphical database...
157 if (fpViewer) {
158 fpViewer -> SetView ();
159 fpViewer -> ClearView ();
160 fpViewer -> DrawView ();
161 }
162}
163
164void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
165{
166 if (fReadyForTransients) {
167 // Always draw transient solids, e.g., hits represented as solids.
168 // (As we have no control over the order of drawing of transient
169 // objects, we cannot do anything about transparent ones, as
170 // below, so always draw them.)
171 G4VSceneHandler::RequestPrimitives (solid);
172 return;
173 }
174
175 // For non-transient (run-duration) objects, ensure transparent
176 // objects are drawn last. The problem of
177 // blending/transparency/alpha is quite a tricky one - see History
178 // of opengl-V07-01-01/2/3.
179 // Get vis attributes - pick up defaults if none.
180 const G4VisAttributes* pVA =
181 fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
182 const G4Colour& c = pVA -> GetColour ();
183 G4double opacity = c.GetAlpha ();
184
185 if (!fSecondPass) {
186 G4bool transparency_enabled = true;
187 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
188 if (pViewer) transparency_enabled = pViewer->transparency_enabled;
189 if (transparency_enabled && opacity < 1.) {
190 // On first pass, transparent objects are not drawn, but flag is set...
191 fSecondPassRequested = true;
192 return;
193 }
194 }
195
196 // On second pass, opaque objects are not drwan...
197 if (fSecondPass && opacity >= 1.) return;
198
199 // Else invoke base class method...
200 G4VSceneHandler::RequestPrimitives (solid);
201}
202
203G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
204
205#endif
Note: See TracBrowser for help on using the repository browser.