… | |
… | |
8 | |
8 | |
9 | #include <GL/glext.h> |
9 | #include <GL/glext.h> |
10 | |
10 | |
11 | entity_base::entity_base () |
11 | entity_base::entity_base () |
12 | { |
12 | { |
13 | orig.x = orig.y = orig.z = 0; |
|
|
14 | } |
13 | } |
15 | |
14 | |
16 | entity_base::~entity_base () |
15 | entity_base::~entity_base () |
17 | { |
16 | { |
18 | hide (); |
17 | hide (); |
… | |
… | |
100 | |
99 | |
101 | clear (); |
100 | clear (); |
102 | } |
101 | } |
103 | |
102 | |
104 | ///////////////////////////////////////////////////////////////////////////// |
103 | ///////////////////////////////////////////////////////////////////////////// |
|
|
104 | |
|
|
105 | entity_opengl::entity_opengl () |
|
|
106 | { |
|
|
107 | list = glGenLists (1); |
|
|
108 | } |
|
|
109 | |
|
|
110 | entity_opengl::~entity_opengl () |
|
|
111 | { |
|
|
112 | glDeleteLists (list, 1); |
|
|
113 | } |
105 | |
114 | |
106 | template class entity_opengl1d<GL_POINTS>; |
115 | template class entity_opengl1d<GL_POINTS>; |
107 | template class entity_opengl1d<GL_LINES>; |
116 | template class entity_opengl1d<GL_LINES>; |
108 | template class entity_opengl1d<GL_LINE_STRIP>; |
117 | template class entity_opengl1d<GL_LINE_STRIP>; |
109 | template class entity_opengl1d<GL_LINE_LOOP>; |
118 | template class entity_opengl1d<GL_LINE_LOOP>; |
… | |
… | |
124 | |
133 | |
125 | entity_base::update_bbox (); |
134 | entity_base::update_bbox (); |
126 | } |
135 | } |
127 | |
136 | |
128 | template<GLenum type> |
137 | template<GLenum type> |
129 | void entity_opengl2d<type>::update_bbox () |
|
|
130 | { |
|
|
131 | for (vector<vertex2d>::iterator i = end (); i-- != begin (); ) |
|
|
132 | bbox.add (i->p); |
|
|
133 | |
|
|
134 | entity_base::update_bbox (); |
|
|
135 | } |
|
|
136 | |
|
|
137 | template<GLenum type> |
|
|
138 | void entity_opengl1d<type>::draw (draw_context &ctx) |
138 | void entity_opengl1d<type>::draw (draw_context &ctx) |
139 | { |
139 | { |
140 | glBegin (type); |
140 | glBegin (type); |
141 | |
141 | |
142 | for (iterator i = begin (); i < end (); ++i) |
142 | for (iterator i = begin (); i < end (); ++i) |
… | |
… | |
147 | |
147 | |
148 | glEnd (); |
148 | glEnd (); |
149 | } |
149 | } |
150 | |
150 | |
151 | template<GLenum type> |
151 | template<GLenum type> |
|
|
152 | void entity_opengl2d<type>::set (const vector<vertex2d> &v) |
|
|
153 | { |
|
|
154 | bbox.reset (); |
|
|
155 | |
|
|
156 | for (vector<vertex2d>::const_iterator i = v.end (); i-- != v.begin (); ) |
|
|
157 | bbox.add (i->p); |
|
|
158 | |
|
|
159 | glNewList (list, GL_COMPILE); |
|
|
160 | |
|
|
161 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse); |
|
|
162 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular); |
|
|
163 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&m.emission); |
|
|
164 | glMaterialf (GL_FRONT, GL_SHININESS, m.shininess); |
|
|
165 | |
|
|
166 | #if 0 |
|
|
167 | glBegin (type); |
|
|
168 | |
|
|
169 | for (iterator i = begin (); i < end (); ++i) |
|
|
170 | { |
|
|
171 | glTexCoord2fv ((GLfloat *)&i->t); |
|
|
172 | glNormal3fv ((GLfloat *)&i->n); |
|
|
173 | glVertex3fv ((GLfloat *)&i->p); |
|
|
174 | } |
|
|
175 | |
|
|
176 | glEnd (); |
|
|
177 | #else |
|
|
178 | glEnableClientState (GL_VERTEX_ARRAY); |
|
|
179 | glVertexPointer (3, GL_FLOAT, sizeof (vertex2d), (void *)&v.begin ()->p); |
|
|
180 | glEnableClientState (GL_NORMAL_ARRAY); |
|
|
181 | glNormalPointer (GL_FLOAT, sizeof (vertex2d), (void *)&v.begin ()->n); |
|
|
182 | glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
|
|
183 | glTexCoordPointer (2, GL_FLOAT, sizeof (vertex2d), (void *)&v.begin ()->t); |
|
|
184 | |
|
|
185 | glDrawArrays (type, 0, v.size ()); |
|
|
186 | #endif |
|
|
187 | |
|
|
188 | glEndList (); |
|
|
189 | } |
|
|
190 | |
|
|
191 | template<GLenum type> |
152 | void entity_opengl2d<type>::draw (draw_context &ctx) |
192 | void entity_opengl2d<type>::draw (draw_context &ctx) |
153 | { |
193 | { |
154 | if (!list) |
|
|
155 | { |
|
|
156 | list = glGenLists (1); |
|
|
157 | glNewList (list, GL_COMPILE); |
|
|
158 | |
|
|
159 | glMaterialfv (GL_FRONT, GL_DIFFUSE, (GLfloat *)&m.diffuse); |
|
|
160 | glMaterialfv (GL_FRONT, GL_SPECULAR, (GLfloat *)&m.specular); |
|
|
161 | glMaterialfv (GL_FRONT, GL_EMISSION, (GLfloat *)&m.emission); |
|
|
162 | glMaterialf (GL_FRONT, GL_SHININESS, m.shininess); |
|
|
163 | |
|
|
164 | #if 0 |
|
|
165 | glBegin (type); |
|
|
166 | |
|
|
167 | for (iterator i = begin (); i < end (); ++i) |
|
|
168 | { |
|
|
169 | glTexCoord2fv ((GLfloat *)&i->t); |
|
|
170 | glNormal3fv ((GLfloat *)&i->n); |
|
|
171 | glVertex3fv ((GLfloat *)&i->p); |
|
|
172 | } |
|
|
173 | |
|
|
174 | glEnd (); |
|
|
175 | #else |
|
|
176 | glEnableClientState (GL_VERTEX_ARRAY); |
|
|
177 | glVertexPointer (3, GL_FLOAT, sizeof (vertex2d), (void *)&begin ()->p); |
|
|
178 | glEnableClientState (GL_NORMAL_ARRAY); |
|
|
179 | glNormalPointer (GL_FLOAT, sizeof (vertex2d), (void *)&begin ()->n); |
|
|
180 | glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
|
|
181 | glTexCoordPointer (2, GL_FLOAT, sizeof (vertex2d), (void *)&begin ()->t); |
|
|
182 | |
|
|
183 | glDrawArrays (type, 0, size ()); |
|
|
184 | #endif |
|
|
185 | |
|
|
186 | glEndList (); |
|
|
187 | |
|
|
188 | clear (); |
|
|
189 | } |
|
|
190 | |
|
|
191 | glPushMatrix (); |
194 | glPushMatrix (); |
192 | const sector &corig = ctx.v.orig; |
195 | const sector &corig = ctx.v.orig; |
193 | glTranslatef (corig.x - orig.x, corig.y - orig.y, corig.z - orig.z); |
196 | glTranslatef (corig.x - orig.x, corig.y - orig.y, corig.z - orig.z); |
194 | glCallList (list); |
197 | glCallList (list); |
195 | glPopMatrix (); |
198 | glPopMatrix (); |