zenilib: zenilib/jni/external/zenilib/zeni_graphics/Vertex3f.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vertex3f.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <zeni_graphics.h>
19
20 #include <cassert>
21
22 #ifndef DISABLE_DX9
23 #include <d3dx9.h>
24 #endif
25
26 #ifndef DISABLE_GL
27 #if defined(REQUIRE_GL_ES)
28 #include <GLES/gl.h>
29 #else
30 #include <GL/glew.h>
31 #endif
32 #endif
33
34 #if defined(_DEBUG) && defined(_WINDOWS)
35 #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
36 #define new DEBUG_NEW
37 #endif
38
39 #include <Zeni/Line_Segment.hxx>
40 #include <Zeni/Quadrilateral.hxx>
41 #include <Zeni/Triangle.hxx>
42
43 namespace Zeni {
44
45 template class Line_Segment<Vertex3f_Color>;
46 template class Line_Segment<Vertex3f_Texture>;
47 template class Quadrilateral<Vertex3f_Color>;
48 template class Quadrilateral<Vertex3f_Texture>;
49 template class Triangle<Vertex3f_Color>;
50 template class Triangle<Vertex3f_Texture>;
51
52 Vertex3f::Vertex3f()
53 {
54 }
55
56 Vertex3f::Vertex3f(const Point3f &position, const Point3f &normal)
57 : position(position),
58 normal(normal)
59 {
60 }
61
62 Vertex3f::~Vertex3f() {
63 }
64
65 Point3f Vertex3f::get_position() const {
66 return position;
67 }
68
69 Vertex3f_Color * Vertex3f_Color::interpolate_to(const float &rhs_part, const Vertex3f_Color &rhs) const {
70 return new Vertex3f_Color(position.interpolate_to(rhs_part, rhs.position),
71 0.5f*(normal + rhs.normal),
72 Color(m_argb).interpolate_to(rhs_part, Color(rhs.m_argb)).get_argb());
73 }
74
75 Vertex3f_Color::Vertex3f_Color()
76 {
77 }
78
79 Vertex3f_Color::Vertex3f_Color(const Point3f &position, const Point3f &normal, const Color &color)
80 : Vertex3f(position, normal),
81 m_argb(color.get_argb())
82 {
83 }
84
85 Vertex3f_Color::Vertex3f_Color(const Point3f &position, const Point3f &normal, const Uint32 &argb)
86 : Vertex3f(position, normal),
87 m_argb(argb)
88 {
89 }
90
91 Vertex3f_Color::Vertex3f_Color(const Point3f &position_, const Color &color)
92 : Vertex3f(position_),
93 m_argb(color.get_argb())
94 {
95 }
96
97 Vertex3f_Color::Vertex3f_Color(const Point3f &position_, const Uint32 &argb_)
98 : Vertex3f(position_),
99 m_argb(argb_)
100 {
101 }
102
103 bool Vertex3f_Color::is_3d() const {
104 return true;
105 }
106
107 #ifndef DISABLE_GL_FIXED
108 void Vertex3f_Color::render_to(Video_GL_Fixed &screen) const {
109 glBegin(GL_POINTS);
110 subrender_to(screen);
111 glEnd();
112 }
113
114 void Vertex3f_Color::subrender_to(Video_GL_Fixed &) const {
115 glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
116 GLubyte((m_argb >> 8) & 0xFF),
117 GLubyte(m_argb & 0xFF),
118 GLubyte((m_argb >> 24) & 0xFF));
119 glNormal3f(normal.x, normal.y, normal.z);
120 glVertex3f(position.x, position.y, position.z);
121 }
122 #endif
123
124 #ifndef DISABLE_GL_SHADER
125 template <>
126 void Line_Segment<Vertex3f_Color>::render_to(Video_GL_Shader &) const {
127 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
128 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00))};
129
130 glEnableClientState(GL_VERTEX_ARRAY);
131 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
132 glEnableClientState(GL_COLOR_ARRAY);
133 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
134
135 glDrawArrays(GL_LINES, 0, 2);
136
137 glDisableClientState(GL_COLOR_ARRAY);
138 glDisableClientState(GL_VERTEX_ARRAY);
139 }
140
141 template <>
142 void Triangle<Vertex3f_Color>::render_to(Video_GL_Shader &) const {
143 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
144 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00)),
145 ((c.get_Color() & 0x000000FF) << 16) | ((c.get_Color() & 0x00FF0000) >> 16) | ((c.get_Color() & 0xFF00FF00))};
146
147 glEnableClientState(GL_VERTEX_ARRAY);
148 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
149 glEnableClientState(GL_COLOR_ARRAY);
150 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
151
152 glDrawArrays(GL_TRIANGLES, 0, 3);
153
154 glDisableClientState(GL_COLOR_ARRAY);
155 glDisableClientState(GL_VERTEX_ARRAY);
156 }
157
158 template <>
159 void Quadrilateral<Vertex3f_Color>::render_to(Video_GL_Shader &) const {
160 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
161 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00)),
162 ((c.get_Color() & 0x000000FF) << 16) | ((c.get_Color() & 0x00FF0000) >> 16) | ((c.get_Color() & 0xFF00FF00)),
163 ((d.get_Color() & 0x000000FF) << 16) | ((d.get_Color() & 0x00FF0000) >> 16) | ((d.get_Color() & 0xFF00FF00))};
164
165 glEnableClientState(GL_VERTEX_ARRAY);
166 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
167 glEnableClientState(GL_COLOR_ARRAY);
168 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
169
170 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
171
172 glDisableClientState(GL_COLOR_ARRAY);
173 glDisableClientState(GL_VERTEX_ARRAY);
174 }
175
176 void Vertex3f_Color::render_to(Video_GL_Shader &) const {
177 Uint32 c4ub = ((m_argb & 0x000000FF) << 16) | ((m_argb & 0x00FF0000) >> 16) | ((m_argb & 0xFF00FF00));
178
179 glEnableClientState(GL_VERTEX_ARRAY);
180 glVertexPointer(3, GL_FLOAT, 0, get_address());
181 glEnableClientState(GL_COLOR_ARRAY);
182 glColorPointer(4, GL_UNSIGNED_BYTE, 0, &c4ub);
183
184 glDrawArrays(GL_POINTS, 0, 1);
185
186 glDisableClientState(GL_COLOR_ARRAY);
187 glDisableClientState(GL_VERTEX_ARRAY);
188 }
189
190 void Vertex3f_Color::subrender_to(Video_GL_Shader &) const {
192 glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
193 GLubyte((m_argb >> 8) & 0xFF),
194 GLubyte(m_argb & 0xFF),
195 GLubyte((m_argb >> 24) & 0xFF));
196 glNormal3f(normal.x, normal.y, normal.z);
197 glVertex3f(position.x, position.y, position.z);
198 }
199 #endif
200
201 #ifndef DISABLE_DX9
202 void Vertex3f_Color::render_to(Video_DX9 &screen) const {
203 screen.get_d3d_device()->DrawPrimitiveUP(D3DPT_POINTLIST, 1, this, sizeof(Vertex3f_Color));
204 }
205 #endif
206
207 Vertex3f_Texture::Vertex3f_Texture()
208 {
209 }
210
211 Vertex3f_Texture::Vertex3f_Texture(const Point3f &position_, const Point3f &normal_, const Point2f &texture_coordinate_)
212 : Vertex3f(position_, normal_),
213 texture_coordinate(texture_coordinate_)
214 {
215 }
216
217 Vertex3f_Texture::Vertex3f_Texture(const Point3f &position, const Point2f &texture_coordinate_)
218 : Vertex3f(position),
219 texture_coordinate(texture_coordinate_)
220 {
221 }
222
223 Vertex3f_Texture * Vertex3f_Texture::interpolate_to(const float &rhs_part, const Vertex3f_Texture &rhs) const {
224 return new Vertex3f_Texture(position.interpolate_to(rhs_part, rhs.position),
225 0.5f*(normal + rhs.normal),
226 texture_coordinate.interpolate_to(rhs_part, rhs.texture_coordinate));
227 }
228
229 bool Vertex3f_Texture::is_3d() const {
230 return true;
231 }
232
233 #ifndef DISABLE_GL_FIXED
234 void Vertex3f_Texture::render_to(Video_GL_Fixed &) const {
235 assert(false);
236 }
237
238 void Vertex3f_Texture::subrender_to(Video_GL_Fixed &) const {
239 glTexCoord2f(texture_coordinate.x, texture_coordinate.y);
240 glNormal3f(normal.x, normal.y, normal.z);
241 glVertex3f(position.x, position.y, position.z);
242 }
243 #endif
244
245 #ifndef DISABLE_GL_SHADER
246 template <>
247 void Line_Segment<Vertex3f_Texture>::render_to(Video_GL_Shader &) const {
248 glEnableClientState(GL_VERTEX_ARRAY);
249 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
250 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
251 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
252
253 glDrawArrays(GL_LINES, 0, 2);
254
255 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
256 glDisableClientState(GL_VERTEX_ARRAY);
257 }
258
259 template <>
260 void Triangle<Vertex3f_Texture>::render_to(Video_GL_Shader &) const {
261 glEnableClientState(GL_VERTEX_ARRAY);
262 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
263 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
264 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
265
266 glDrawArrays(GL_TRIANGLES, 0, 3);
267
268 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
269 glDisableClientState(GL_VERTEX_ARRAY);
270 }
271
272 template <>
273 void Quadrilateral<Vertex3f_Texture>::render_to(Video_GL_Shader &) const {
274 glEnableClientState(GL_VERTEX_ARRAY);
275 glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
276 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
277 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
278
279 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
280
281 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
282 glDisableClientState(GL_VERTEX_ARRAY);
283 }
284
285 void Vertex3f_Texture::render_to(Video_GL_Shader &) const {
286 assert(false);
287 }
288
289 void Vertex3f_Texture::subrender_to(Video_GL_Shader &) const {
291 glTexCoord2f(texture_coordinate.x, texture_coordinate.y);
292 glNormal3f(normal.x, normal.y, normal.z);
293 glVertex3f(position.x, position.y, position.z);
294 }
295 #endif
296
297 #ifndef DISABLE_DX9
298 void Vertex3f_Texture::render_to(Video_DX9 &) const {
299 assert(false);
300 }
301 #endif
302
303 }
Quadrilateral.hxx
Zeni::Vertex3f
Definition: Vertex3f.h:56
Triangle.hxx
Zeni::Vertex3f_Color::subrender_to
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex3f.cpp:114
Zeni::Video_DX9
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
Zeni::Video_DX9::get_d3d_device
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
GL_VERTEX_ARRAY
#define GL_VERTEX_ARRAY
Definition: glew_head.h:723
color
GLuint color
Definition: glew.h:7185
GL_LINES
#define GL_LINES
Definition: gl2.h:55
Zeni::Vertex3f_Color::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex3f.cpp:108
Zeni::Vertex3f_Color
An Abstraction of a Vertex in 3-space, colored.
Definition: Vertex3f.h:76
Zeni::Vertex3f_Texture::interpolate_to
Vertex3f_Texture * interpolate_to(const float &rhs_part, const Vertex3f_Texture &rhs) const
Get a Vertex2f_Texture between two vertices; rhs must be a Vertex2f_Texture.
Definition: Vertex3f.cpp:223
Zeni::Vertex3f_Texture::subrender_to
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex3f.cpp:238
D3DPT_POINTLIST
Definition: d3d9types.h:304
Zeni::Line_Segment::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Line_Segment.hxx:76
Zeni::Vertex3f_Texture::Vertex3f_Texture
Vertex3f_Texture()
Initialize the Vertex3f_Texture.
Definition: Vertex3f.cpp:207
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
Zeni::Vertex3f_Texture
An Abstraction of a Vertex in 3-space, textured.
Definition: Vertex3f.h:113
d
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
assert
#define assert(x)
Definition: SDL_malloc.c:1234
Zeni::Vertex3f::position
Point3f position
Definition: Vertex3f.h:72
GL_TRIANGLE_FAN
#define GL_TRIANGLE_FAN
Definition: gl2.h:60
d3dx9.h
Zeni::Vertex3f_Texture::texture_coordinate
Point2f texture_coordinate
Definition: Vertex3f.h:143
Zeni::Vertex3f::get_address
void * get_address() const
A bit of a hack, necessary to memcpy data into Vertex_Buffers.
Definition: Vertex3f.hxx:25
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
GL_COLOR_ARRAY
#define GL_COLOR_ARRAY
Definition: glew_head.h:725
glColor4ub
#define glColor4ub
Definition: gl_mangle.h:212
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
Line_Segment.hxx
Zeni::Point2f::y
float y
Definition: Coordinate.h:117
glVertex3f
#define glVertex3f
Definition: gl_mangle.h:1946
glTexCoord2f
#define glTexCoord2f
Definition: gl_mangle.h:1692
GL_TRIANGLES
#define GL_TRIANGLES
Definition: gl2.h:58
GLubyte
khronos_uint8_t GLubyte
Definition: gl2.h:30
Zeni::Video_GL_Fixed
The OpenGL Rendering System.
Definition: Video_GL_Fixed.h:70
Zeni::Vertex3f::get_position
virtual Point3f get_position() const
Definition: Vertex3f.cpp:65
GL_POINTS
#define GL_POINTS
Definition: gl2.h:54
Zeni::Quadrilateral::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Quadrilateral.hxx:85
c
const GLfloat * c
Definition: glew.h:14913
glNormal3f
#define glNormal3f
Definition: gl_mangle.h:1224
Zeni::Color::interpolate_to
Color interpolate_to(const float &rhs_part, const Color &rhs) const
Get a color that is inbetween this color and another color.
Definition: Color.cpp:46
Zeni::Video_GL_Shader
The OpenGL Rendering System.
Definition: Video_GL_Shader.h:70
GL_TEXTURE_COORD_ARRAY
#define GL_TEXTURE_COORD_ARRAY
Definition: glew_head.h:727
Zeni::Point3f::y
float y
Definition: Coordinate.h:152
Zeni::Point2f::x
float x
Definition: Coordinate.h:117
Zeni::Point3f::z
float z
Definition: Coordinate.h:152
glDisableClientState
#define glDisableClientState
Definition: gl_mangle.h:390
glTexCoordPointer
#define glTexCoordPointer
Definition: gl_mangle.h:1739
glColorPointer
#define glColorPointer
Definition: gl_mangle.h:236
Zeni::Triangle::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Triangle.hxx:85
Zeni::Vertex3f::~Vertex3f
virtual ~Vertex3f()
Definition: Vertex3f.cpp:62
glEnableClientState
#define glEnableClientState
Definition: gl_mangle.h:438
GL_UNSIGNED_BYTE
#define GL_UNSIGNED_BYTE
Definition: gl2.h:236
Zeni::Vertex3f_Texture::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex3f.cpp:234
Zeni::Vertex3f_Color::interpolate_to
Vertex3f_Color * interpolate_to(const float &rhs_part, const Vertex3f_Color &rhs) const
Get a Vertex3f_Color between two vertices; rhs must be a Vertex3f_Color.
Definition: Vertex3f.cpp:69
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
glBegin
#define glBegin
Definition: gl_mangle.h:56
GL_FLOAT
#define GL_FLOAT
Definition: gl2.h:241
glVertexPointer
#define glVertexPointer
Definition: gl_mangle.h:2196
glEnd
#define glEnd
Definition: gl_mangle.h:450
Zeni::Point2f::interpolate_to
Point2f interpolate_to(const float &rhs_part, const Point2f &rhs) const
Get a point inbetween this point and another point of the same type.
Definition: Coordinate.cpp:28
Zeni::Vertex3f_Texture::is_3d
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex3f.cpp:229
zeni_graphics.h
Zeni::Vertex3f::normal
Point3f normal
Definition: Vertex3f.h:73
glDrawArrays
#define glDrawArrays
Definition: gl_mangle.h:403
Zeni::Point3f::interpolate_to
Point3f interpolate_to(const float &rhs_part, const Point3f &rhs) const
Definition: Coordinate.cpp:41
Zeni::Color::get_argb
Uint32 get_argb() const
Get a Uint32 representation of 0xAARRGGBB.
Definition: Color.hxx:47
Zeni::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Vertex3f_Color::Vertex3f_Color
Vertex3f_Color()
Initialize the Vertex3f_Color.
Definition: Vertex3f.cpp:75
Zeni::Vertex3f_Color::is_3d
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex3f.cpp:103
Zeni::Vertex3f::Vertex3f
Vertex3f()
Definition: Vertex3f.cpp:52
Zeni::Color
Color.
Definition: Color.h:41
Zeni::Point3f::x
float x
Definition: Coordinate.h:152