ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
(Generate patch)

Comparing libgender/view.C (file contents):
Revision 1.4 by root, Mon Oct 4 07:04:58 2004 UTC vs.
Revision 1.32 by root, Wed Oct 6 17:55:40 2004 UTC

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
6draw_context::draw_context (view &v) 9 static GLenum gl_error;
7: v(v), l(0), mode(LIGHTED) 10view::view ()
11: gamma(1.0)
8{ 12{
9} 13}
10 14
11draw_context::~draw_context () 15view::~view ()
12{ 16{
13} 17}
14 18
15bool draw_context::may_draw (entity_base *e) 19bool view::may_draw (entity_base *e)
16{ 20{
17 if (drawn.find (e) != drawn.end ()) 21 if (drawn.find (e) != drawn.end ())
18 return false; 22 return false;
19 23
20 drawn.insert (e); 24 drawn.insert (e);
21 return true; 25 return true;
22} 26}
23 27
24void view::draw (draw_context &ctx) 28void view::reset_projection ()
25{ 29{
30 renormalize (orig, p);
31
32 glViewport (0, 0, w, h);
33
34 glMatrixMode (GL_PROJECTION);
35 glLoadIdentity ();
36
37 gl_error = glGetError ();
38 GLdouble aspect = (GLdouble)w/h;
39 GLdouble zNear = 0.1;
40 GLdouble zFar = 50.;
41
42 gl_error = glGetError ();
43 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
44 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
45
46 gl_error = glGetError ();
47 d = normalize (d);//D
48 u = normalize (u);//D
49 vec3 rz = -d;
50 vec3 rx = cross (u, rz);
51 vec3 ry = cross (rz, rx);
52 gl_error = glGetError ();
53
54 matrix &m = projection;
55 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
56 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
57 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
58 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
59 gl_error = glGetError ();
60
61 glMultMatrixf ((GLfloat *)m.data);
62
63 gl_error = glGetError ();
64 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
65
66 gl_error = glGetError ();
67 frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) );
68 frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) );
69 frustum.b = plane ( m(3,0) + m(1,0), m(3,1) + m(1,1), m(3,2) + m(1,2), m(3,3) + m(1,3) );
70 frustum.t = plane ( m(3,0) - m(1,0), m(3,1) - m(1,1), m(3,2) - m(1,2), m(3,3) - m(1,3) );
71 frustum.n = 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) );
72 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) );
73
74 gl_error = glGetError ();
75 glMatrixMode (GL_MODELVIEW);
76 glLoadIdentity ();
77 glTranslatef (-p.x, -p.y, -p.z);
78 gl_error = glGetError ();
79}
80
81void view::begin ()
82{
83 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
84 glDepthRange (0, 1. - (1. / pow (2., 16.)));
85
86 vismap.clear ();
87 vislist.clear ();
88
89 generation++;
90
91 reset_projection ();
92
93 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
94 ;
95 farlist.clear ();
96
26 // check occlusion queries here 97 // check occlusion queries here
98#if 0
99 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
100 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
101 occ_query_result ((*i)->occ_query);
27 102
28 ctx.generation++; 103 checklist.clear ();
104#endif
29 105
30 //renormalize (orig, p); 106 world.detect_visibility (*this);
107}
31 108
32 if (ctx.mode == draw_context::DEPTH) 109void view::end ()
110{
111 vismap.clear ();
112}
113
114void view::pass (enum mode m)
115{
116 mode = m;
117
118 glDisable (GL_ALPHA_TEST);
119 glDisable (GL_BLEND);
120
121 if (mode == view::DEPTH)
33 { 122 {
34 glEnable (GL_POLYGON_OFFSET_FILL); 123 glEnable (GL_POLYGON_OFFSET_FILL);
35 glPolygonOffset (0, 1); 124 glPolygonOffset (0, 1);
36 glDepthFunc (GL_LESS); 125 glDepthFunc (GL_LESS);
37 glDisable (GL_LIGHTING); 126 glDisable (GL_LIGHTING);
38 glColorMask (0, 0, 0, 0); 127 glColorMask (0, 0, 0, 0);
128 cgGLEnableProfile (vsh_profile);// z-fighting??
129 cgGLDisableProfile (fsh_profile);
39 } 130 }
40 else 131 else
41 { 132 {
133 glEnable (GL_MINMAX);
42 glDisable (GL_POLYGON_OFFSET_FILL); 134 glDisable (GL_POLYGON_OFFSET_FILL);
43 glDrawBuffer (GL_BACK);
44 glDepthFunc (GL_LEQUAL); 135 glDepthFunc (GL_LESS);
45 glEnable (GL_LIGHTING);
46 glDepthMask (0); 136 glDepthMask (0);
137 cgGLEnableProfile (vsh_profile);
138 cgGLEnableProfile (fsh_profile);
47 } 139 }
48 140
49 glViewport (0, 0, w, h); 141 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
142 (*i)->display (*this);
50 143
51 glMatrixMode (GL_PROJECTION); 144 drawn.clear ();
52 glLoadIdentity ();
53 145
54 GLdouble aspect = (GLdouble)w/h; 146 if (mode == view::LIGHTED)
55 GLdouble zNear = 0.001; 147 {
56 GLdouble zFar = 100.; 148 glEnable (GL_DEPTH_CLAMP_NV);
149 glDepthFunc (GL_LESS);
150 glEnable (GL_COLOR_MATERIAL);
151 glDisable (GL_LIGHTING);
152#if 1
153 cgGLDisableProfile (vsh_profile);
154 cgGLDisableProfile (fsh_profile);
155#endif
156 glShadeModel (GL_FLAT);
57 157
58 GLdouble ymax = zNear * tan (fov * (M_PI / 360.0)); 158 static int count; count++;
59 glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar); 159 if (farlist.size ())
160 printf ("%d: size %d\n", count, farlist.size ());
60 161
61 vec3 rz = -d; 162 for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
62 vec3 rx = cross (u, rz); 163 {
63 vec3 ry = cross (rz, rx); 164 glColor3f (1 / (GLfloat)(i - farlist.begin()), 1, 1 / (GLfloat)(i - farlist.begin()));
165 (*i)->draw_bbox (*this);
166 }
64 167
65 gl_matrix &m = ctx.projection; 168 glEnable (GL_DEPTH_TEST);
66 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0; 169 glDisable (GL_DEPTH_CLAMP_NV);
67 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0; 170 glShadeModel (GL_SMOOTH);
68 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0; 171 }
69 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
70
71 glMultMatrixf ((GLfloat *)m.data);
72
73 glMatrixMode (GL_MODELVIEW);
74 glLoadIdentity ();
75 glTranslatef (-p.x, -p.y, -p.z);
76
77 world.draw (ctx);
78
79 ctx.drawn.clear ();
80 172
81 glColorMask (1, 1, 1, 0); 173 glColorMask (1, 1, 1, 0);
82 glDepthMask (1); 174 glDepthMask (1);
175
83} 176}
84 177
178

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines