1 | #include <cmath> |
1 | #include <cmath> |
|
|
2 | |
|
|
3 | #include <GL/gl.h> |
|
|
4 | #include <GL/glext.h> |
2 | |
5 | |
3 | #include "oct.h" |
6 | #include "oct.h" |
4 | #include "view.h" |
7 | #include "view.h" |
5 | |
8 | |
6 | view::view () |
9 | view::view () |
7 | : mode(LIGHTED) |
10 | : gamma(1.0) |
8 | { |
11 | { |
9 | } |
12 | } |
10 | |
13 | |
11 | view::~view () |
14 | view::~view () |
12 | { |
15 | { |
… | |
… | |
19 | |
22 | |
20 | drawn.insert (e); |
23 | drawn.insert (e); |
21 | return true; |
24 | return true; |
22 | } |
25 | } |
23 | |
26 | |
24 | void view::draw () |
27 | void view::reset_projection () |
25 | { |
28 | { |
26 | // check occlusion queries here |
|
|
27 | |
|
|
28 | generation++; |
|
|
29 | |
|
|
30 | renormalize (orig, p); |
29 | renormalize (orig, p); |
31 | |
30 | |
32 | glDisable (GL_ALPHA_TEST); |
|
|
33 | glDisable (GL_BLEND); |
|
|
34 | |
|
|
35 | if (mode == view::DEPTH) |
|
|
36 | { |
|
|
37 | glEnable (GL_POLYGON_OFFSET_FILL); |
|
|
38 | glPolygonOffset (0, 1); |
|
|
39 | glDepthFunc (GL_LESS); |
|
|
40 | glDisable (GL_LIGHTING); |
|
|
41 | glColorMask (0, 0, 0, 0); |
|
|
42 | //cgGLDisableProfile (CG_PROFILE_ARBVP1); |
|
|
43 | cgGLDisableProfile (CG_PROFILE_ARBFP1); |
|
|
44 | } |
|
|
45 | else |
|
|
46 | { |
|
|
47 | glEnable (GL_MINMAX); |
|
|
48 | glDisable (GL_POLYGON_OFFSET_FILL); |
|
|
49 | glDepthFunc (GL_LESS); |
|
|
50 | glDepthMask (0); |
|
|
51 | cgGLEnableProfile (CG_PROFILE_ARBVP1); |
|
|
52 | cgGLEnableProfile (CG_PROFILE_ARBFP1); |
|
|
53 | } |
|
|
54 | |
|
|
55 | glViewport (0, 0, w, h); |
31 | glViewport (0, 0, w, h); |
56 | |
32 | |
57 | glMatrixMode (GL_PROJECTION); |
33 | glMatrixMode (GL_PROJECTION); |
58 | glLoadIdentity (); |
34 | glLoadIdentity (); |
59 | |
35 | |
… | |
… | |
88 | frustum.f = plane ( m(3,0) - m(2,0), m(3,1) - m(2,1), m(3,2) - m(2,2), m(3,3) - m(2,3) ); |
64 | frustum.f = plane ( m(3,0) - m(2,0), m(3,1) - m(2,1), m(3,2) - m(2,2), m(3,3) - m(2,3) ); |
89 | |
65 | |
90 | glMatrixMode (GL_MODELVIEW); |
66 | glMatrixMode (GL_MODELVIEW); |
91 | glLoadIdentity (); |
67 | glLoadIdentity (); |
92 | glTranslatef (-p.x, -p.y, -p.z); |
68 | glTranslatef (-p.x, -p.y, -p.z); |
|
|
69 | } |
93 | |
70 | |
|
|
71 | void view::begin () |
|
|
72 | { |
|
|
73 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
|
|
74 | glDepthRange (0, 1. - (1. / pow (2., 16.))); |
|
|
75 | |
|
|
76 | vismap.clear (); |
94 | vislist.clear (); |
77 | vislist.clear (); |
|
|
78 | |
|
|
79 | generation++; |
|
|
80 | |
|
|
81 | reset_projection (); |
|
|
82 | |
|
|
83 | // check occlusion queries here |
|
|
84 | #if 0 |
|
|
85 | for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i) |
|
|
86 | //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query)); |
|
|
87 | occ_query_result ((*i)->occ_query); |
|
|
88 | |
95 | checklist.clear (); |
89 | checklist.clear (); |
|
|
90 | #endif |
|
|
91 | |
96 | world.detect_visibility (*this); |
92 | world.detect_visibility (*this); |
|
|
93 | } |
97 | |
94 | |
|
|
95 | void view::end () |
|
|
96 | { |
|
|
97 | vismap.clear (); |
|
|
98 | } |
|
|
99 | |
|
|
100 | void view::pass (enum mode m) |
|
|
101 | { |
|
|
102 | mode = m; |
|
|
103 | |
|
|
104 | glDisable (GL_ALPHA_TEST); |
|
|
105 | glDisable (GL_BLEND); |
|
|
106 | |
|
|
107 | if (mode == view::DEPTH) |
|
|
108 | { |
|
|
109 | glEnable (GL_POLYGON_OFFSET_FILL); |
|
|
110 | glPolygonOffset (0, 1); |
|
|
111 | glDepthFunc (GL_LESS); |
|
|
112 | glDisable (GL_LIGHTING); |
|
|
113 | glColorMask (0, 0, 0, 0); |
|
|
114 | cgGLEnableProfile (vsh_profile);// z-fighting?? |
|
|
115 | cgGLDisableProfile (fsh_profile); |
|
|
116 | } |
|
|
117 | else |
|
|
118 | { |
|
|
119 | glEnable (GL_MINMAX); |
|
|
120 | glDisable (GL_POLYGON_OFFSET_FILL); |
|
|
121 | glDepthFunc (GL_LESS); |
|
|
122 | glDepthMask (0); |
|
|
123 | cgGLEnableProfile (vsh_profile); |
|
|
124 | cgGLEnableProfile (fsh_profile); |
|
|
125 | } |
|
|
126 | |
98 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
127 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
99 | (*i)->display (*this); |
128 | (*i)->display (*this); |
100 | |
129 | |
101 | drawn.clear (); |
130 | drawn.clear (); |
102 | |
131 | |
|
|
132 | if (mode == view::LIGHTED) |
|
|
133 | { |
|
|
134 | glEnable (GL_DEPTH_CLAMP_NV); |
|
|
135 | glDepthFunc (GL_LESS); |
|
|
136 | glEnable (GL_COLOR_MATERIAL); |
|
|
137 | glDisable (GL_LIGHTING); |
|
|
138 | #if 1 |
|
|
139 | cgGLDisableProfile (vsh_profile); |
|
|
140 | cgGLDisableProfile (fsh_profile); |
|
|
141 | #endif |
|
|
142 | glShadeModel (GL_FLAT); |
|
|
143 | |
|
|
144 | static int count; count++; |
|
|
145 | if (farlist.size ()) |
|
|
146 | printf ("%d: size %d\n", count, farlist.size ()); |
|
|
147 | |
|
|
148 | for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i) |
|
|
149 | { |
|
|
150 | glColor3f (1 / (GLfloat)(i - farlist.begin()), 1, 1 / (GLfloat)(i - farlist.begin())); |
|
|
151 | (*i)->draw_bbox (*this); |
|
|
152 | } |
|
|
153 | |
|
|
154 | farlist.clear (); |
|
|
155 | |
|
|
156 | glEnable (GL_DEPTH_TEST); |
|
|
157 | glDisable (GL_DEPTH_CLAMP_NV); |
|
|
158 | glShadeModel (GL_SMOOTH); |
|
|
159 | } |
|
|
160 | |
103 | glColorMask (1, 1, 1, 0); |
161 | glColorMask (1, 1, 1, 0); |
104 | glDepthMask (1); |
162 | glDepthMask (1); |
|
|
163 | |
105 | } |
164 | } |
106 | |
165 | |
107 | |
166 | |