zenilib: zenilib/jni/external/zenilib/zeni_graphics/Vertex2f.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
Vertex2f.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<Vertex2f_Color>;
46 template class Line_Segment<Vertex2f_Texture>;
47 template class Quadrilateral<Vertex2f_Color>;
48 template class Quadrilateral<Vertex2f_Texture>;
49 template class Triangle<Vertex2f_Color>;
50 template class Triangle<Vertex2f_Texture>;
51
52 Vertex2f::Vertex2f()
53 {
54 }
55
56 Vertex2f::Vertex2f(const Point2f &position)
57 : position(position.x, position.y, position.z)
58 {
59 }
60
61 Vertex2f::~Vertex2f() {
62 }
63
64 Point3f Vertex2f::get_position() const {
65 return position;
66 }
67
68 Vertex2f_Color * Vertex2f_Color::interpolate_to(const float &rhs_part, const Vertex2f_Color &rhs) const {
69 const Point3f midpt = position.interpolate_to(rhs_part, rhs.position);
70 return new Vertex2f_Color(Point2f(midpt.x, midpt.y),
71 Color(m_argb).interpolate_to(rhs_part, Color(rhs.m_argb)).get_argb());
72 }
73
74 Vertex2f_Color::Vertex2f_Color()
75 {
76 }
77
78 Vertex2f_Color::Vertex2f_Color(const Point2f &position, const Color &color)
79 : Vertex2f(position),
80 m_argb(color.get_argb())
81 {
82 }
83
84 Vertex2f_Color::Vertex2f_Color(const Point2f &position, const Uint32 &argb)
85 : Vertex2f(position),
86 m_argb(argb)
87 {
88 }
89
90 bool Vertex2f_Color::is_3d() const {
91 return false;
92 }
93
94 #ifndef DISABLE_GL_FIXED
95 void Vertex2f_Color::render_to(Video_GL_Fixed &screen) const {
96 glBegin(GL_POINTS);
97 subrender_to(screen);
98 glEnd();
99 }
100
101 void Vertex2f_Color::subrender_to(Video_GL_Fixed &) const {
102 glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
103 GLubyte((m_argb >> 8) & 0xFF),
104 GLubyte(m_argb & 0xFF),
105 GLubyte((m_argb >> 24) & 0xFF));
106 glVertex2f(position.x, position.y);
107 }
108 #endif
109
110 #ifndef DISABLE_GL_SHADER
111 template <>
112 void Line_Segment<Vertex2f_Color>::render_to(Video_GL_Shader &) const {
113 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
114 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00))};
115
116 glEnableClientState(GL_VERTEX_ARRAY);
117 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
118 glEnableClientState(GL_COLOR_ARRAY);
119 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
120
121 glDrawArrays(GL_LINES, 0, 2);
122
123 glDisableClientState(GL_COLOR_ARRAY);
124 glDisableClientState(GL_VERTEX_ARRAY);
125 }
126
127 template <>
128 void Triangle<Vertex2f_Color>::render_to(Video_GL_Shader &) const {
129 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
130 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00)),
131 ((c.get_Color() & 0x000000FF) << 16) | ((c.get_Color() & 0x00FF0000) >> 16) | ((c.get_Color() & 0xFF00FF00))};
132
133 glEnableClientState(GL_VERTEX_ARRAY);
134 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
135 glEnableClientState(GL_COLOR_ARRAY);
136 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
137
138 glDrawArrays(GL_TRIANGLES, 0, 3);
139
140 glDisableClientState(GL_COLOR_ARRAY);
141 glDisableClientState(GL_VERTEX_ARRAY);
142 }
143
144 template <>
145 void Quadrilateral<Vertex2f_Color>::render_to(Video_GL_Shader &) const {
146 Uint32 c4ub[] = {((a.get_Color() & 0x000000FF) << 16) | ((a.get_Color() & 0x00FF0000) >> 16) | ((a.get_Color() & 0xFF00FF00)),
147 ((b.get_Color() & 0x000000FF) << 16) | ((b.get_Color() & 0x00FF0000) >> 16) | ((b.get_Color() & 0xFF00FF00)),
148 ((c.get_Color() & 0x000000FF) << 16) | ((c.get_Color() & 0x00FF0000) >> 16) | ((c.get_Color() & 0xFF00FF00)),
149 ((d.get_Color() & 0x000000FF) << 16) | ((d.get_Color() & 0x00FF0000) >> 16) | ((d.get_Color() & 0xFF00FF00))};
150
151 glEnableClientState(GL_VERTEX_ARRAY);
152 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
153 glEnableClientState(GL_COLOR_ARRAY);
154 glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
155
156 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
157
158 glDisableClientState(GL_COLOR_ARRAY);
159 glDisableClientState(GL_VERTEX_ARRAY);
160 }
161
162 void Vertex2f_Color::render_to(Video_GL_Shader &) const {
163 Uint32 c4ub = ((m_argb & 0x000000FF) << 16) | ((m_argb & 0x00FF0000) >> 16) | ((m_argb & 0xFF00FF00));
164
165 glEnableClientState(GL_VERTEX_ARRAY);
166 glVertexPointer(2, GL_FLOAT, 0, get_address());
167 glEnableClientState(GL_COLOR_ARRAY);
168 glColorPointer(4, GL_UNSIGNED_BYTE, 0, &c4ub);
169
170 glDrawArrays(GL_POINTS, 0, 1);
171
172 glDisableClientState(GL_COLOR_ARRAY);
173 glDisableClientState(GL_VERTEX_ARRAY);
174 }
175
176 void Vertex2f_Color::subrender_to(Video_GL_Shader &) const {
178 glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
179 GLubyte((m_argb >> 8) & 0xFF),
180 GLubyte(m_argb & 0xFF),
181 GLubyte((m_argb >> 24) & 0xFF));
182 glVertex2f(position.x, position.y);
183 }
184 #endif
185
186 #ifndef DISABLE_DX9
187 void Vertex2f_Color::render_to(Video_DX9 &screen) const {
188 screen.get_d3d_device()->DrawPrimitiveUP(D3DPT_POINTLIST, 1, this, sizeof(Vertex2f_Color));
189 }
190 #endif
191
192 Vertex2f_Texture::Vertex2f_Texture()
193 {
194 }
195
196 Vertex2f_Texture::Vertex2f_Texture(const Point2f &position, const Point2f &texture_coordinate_)
197 : Vertex2f(position),
198 texture_coordinate(texture_coordinate_)
199 {
200 }
201
202 Vertex2f_Texture * Vertex2f_Texture::interpolate_to(const float &rhs_part, const Vertex2f_Texture &rhs) const {
203 const Point3f midpt = position.interpolate_to(rhs_part, rhs.position);
204 return new Vertex2f_Texture(Point2f(midpt.x, midpt.y),
205 texture_coordinate.interpolate_to(rhs_part, rhs.texture_coordinate));
206 }
207
208 bool Vertex2f_Texture::is_3d() const {
209 return false;
210 }
211
212 #ifndef DISABLE_GL_FIXED
213 void Vertex2f_Texture::render_to(Video_GL_Fixed &) const {
214 assert(false);
215 }
216
217 void Vertex2f_Texture::subrender_to(Video_GL_Fixed &) const {
218 glTexCoord2f(texture_coordinate.x, texture_coordinate.y);
219 glVertex2f(position.x, position.y);
220 }
221 #endif
222
223 #ifndef DISABLE_GL_SHADER
224 template <>
225 void Line_Segment<Vertex2f_Texture>::render_to(Video_GL_Shader &) const {
226 glEnableClientState(GL_VERTEX_ARRAY);
227 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
228 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
229 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
230
231 glDrawArrays(GL_LINES, 0, 2);
232
233 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
234 glDisableClientState(GL_VERTEX_ARRAY);
235 }
236
237 template <>
238 void Triangle<Vertex2f_Texture>::render_to(Video_GL_Shader &) const {
239 glEnableClientState(GL_VERTEX_ARRAY);
240 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
241 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
242 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
243
244 glDrawArrays(GL_TRIANGLES, 0, 3);
245
246 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
247 glDisableClientState(GL_VERTEX_ARRAY);
248 }
249
250 template <>
251 void Quadrilateral<Vertex2f_Texture>::render_to(Video_GL_Shader &) const {
252 glEnableClientState(GL_VERTEX_ARRAY);
253 glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
254 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
255 glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
256
257 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
258
259 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
260 glDisableClientState(GL_VERTEX_ARRAY);
261 }
262
263 void Vertex2f_Texture::render_to(Video_GL_Shader &) const {
264 assert(false);
265 }
266
267 void Vertex2f_Texture::subrender_to(Video_GL_Shader &) const {
269 glTexCoord2f(texture_coordinate.x, texture_coordinate.y);
270 glVertex2f(position.x, position.y);
271 }
272 #endif
273
274 #ifndef DISABLE_DX9
275 void Vertex2f_Texture::render_to(Video_DX9 &) const {
276 assert(false);
277 }
278 #endif
279
280 }
Quadrilateral.hxx
Zeni::Vertex2f_Color::subrender_to
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex2f.cpp:101
Triangle.hxx
Zeni::Vertex2f_Texture::Vertex2f_Texture
Vertex2f_Texture()
Initialize the Vertex2f_Texture.
Definition: Vertex2f.cpp:192
Zeni::Video_DX9
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
Zeni::Vertex2f::~Vertex2f
virtual ~Vertex2f()
Definition: Vertex2f.cpp:61
Zeni::Video_DX9::get_d3d_device
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
Zeni::Vertex2f_Texture::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex2f.cpp:213
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::Vertex2f_Color
An Abstraction of a Vertex in 2-space, colored.
Definition: Vertex2f.h:80
Zeni::Vertex2f::position
Point3f position
Definition: Vertex2f.h:77
D3DPT_POINTLIST
Definition: d3d9types.h:304
x
EGLSurface EGLint x
Definition: eglext.h:293
Zeni::Line_Segment::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Line_Segment.hxx:76
a
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
Zeni::Vertex2f_Texture::interpolate_to
Vertex2f_Texture * interpolate_to(const float &rhs_part, const Vertex2f_Texture &rhs) const
Get a Vertex2f_Texture between two vertices; rhs must be a Vertex2f_Texture.
Definition: Vertex2f.cpp:202
d
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
assert
#define assert(x)
Definition: SDL_malloc.c:1234
GL_TRIANGLE_FAN
#define GL_TRIANGLE_FAN
Definition: gl2.h:60
glVertex2f
#define glVertex2f
Definition: gl_mangle.h:1936
Zeni::Vertex2f_Color::is_3d
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex2f.cpp:90
d3dx9.h
Zeni::Vertex2f::get_address
void * get_address() const
A bit of a hack, necessary to memcpy data into Vertex_Buffers.
Definition: Vertex2f.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
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
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
Zeni::Video_GL_Shader
The OpenGL Rendering System.
Definition: Video_GL_Shader.h:70
Zeni::Vertex2f_Color::Vertex2f_Color
Vertex2f_Color()
Initialize the Vertex2f_Color.
Definition: Vertex2f.cpp:74
Zeni::Vertex2f
Definition: Vertex2f.h:55
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::Vertex2f_Texture::subrender_to
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex2f.cpp:217
glDisableClientState
#define glDisableClientState
Definition: gl_mangle.h:390
glTexCoordPointer
#define glTexCoordPointer
Definition: gl_mangle.h:1739
Zeni::Vertex2f::get_position
virtual Point3f get_position() const
Definition: Vertex2f.cpp:64
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
y
EGLSurface EGLint EGLint y
Definition: eglext.h:293
Zeni::Vertex2f_Texture
An Abstraction of a Vertex in 2-space, textured.
Definition: Vertex2f.h:115
Zeni::Vertex2f::Vertex2f
Vertex2f()
Definition: Vertex2f.cpp:52
glEnableClientState
#define glEnableClientState
Definition: gl_mangle.h:438
GL_UNSIGNED_BYTE
#define GL_UNSIGNED_BYTE
Definition: gl2.h:236
b
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
z
GLint GLint GLint GLint z
Definition: gl2ext.h:1214
glBegin
#define glBegin
Definition: gl_mangle.h:56
Zeni::Vertex2f_Texture::is_3d
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex2f.cpp:208
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_graphics.h
Zeni::Vertex2f_Color::interpolate_to
Vertex2f_Color * interpolate_to(const float &rhs_part, const Vertex2f_Color &rhs) const
Get a Vertex2f_Color between two vertices; rhs must be a Vertex2f_Color.
Definition: Vertex2f.cpp:68
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::Point2f
A 2D Point represented with floats.
Definition: Coordinate.h:98
Zeni::Vertex2f_Texture::texture_coordinate
Point2f texture_coordinate
Definition: Vertex2f.h:144
Zeni::Vertex2f_Color::render_to
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex2f.cpp:95
Zeni::Color
Color.
Definition: Color.h:41
Zeni::Point3f::x
float x
Definition: Coordinate.h:152