zenilib  0.5.3.0
 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 
53  {
54  }
55 
56  Vertex2f::Vertex2f(const Point2f &position)
57  : position(position.x, position.y, position.z)
58  {
59  }
60 
62  }
63 
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 
75  {
76  }
77 
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
97  subrender_to(screen);
98  glEnd();
99  }
100 
102  glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
103  GLubyte((m_argb >> 8) & 0xFF),
104  GLubyte(m_argb & 0xFF),
105  GLubyte((m_argb >> 24) & 0xFF));
107  }
108 #endif
109 
110 #ifndef DISABLE_GL_SHADER
111  template <>
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 
117  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
119  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
120 
121  glDrawArrays(GL_LINES, 0, 2);
122 
125  }
126 
127  template <>
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 
134  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
136  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
137 
138  glDrawArrays(GL_TRIANGLES, 0, 3);
139 
142  }
143 
144  template <>
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 
152  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
154  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
155 
157 
160  }
161 
163  Uint32 c4ub = ((m_argb & 0x000000FF) << 16) | ((m_argb & 0x00FF0000) >> 16) | ((m_argb & 0xFF00FF00));
164 
168  glColorPointer(4, GL_UNSIGNED_BYTE, 0, &c4ub);
169 
170  glDrawArrays(GL_POINTS, 0, 1);
171 
174  }
175 
178  glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
179  GLubyte((m_argb >> 8) & 0xFF),
180  GLubyte(m_argb & 0xFF),
181  GLubyte((m_argb >> 24) & 0xFF));
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 
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),
206  }
207 
208  bool Vertex2f_Texture::is_3d() const {
209  return false;
210  }
211 
212 #ifndef DISABLE_GL_FIXED
214  assert(false);
215  }
216 
220  }
221 #endif
222 
223 #ifndef DISABLE_GL_SHADER
224  template <>
227  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
229  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
230 
231  glDrawArrays(GL_LINES, 0, 2);
232 
235  }
236 
237  template <>
240  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
242  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
243 
244  glDrawArrays(GL_TRIANGLES, 0, 3);
245 
248  }
249 
250  template <>
253  glVertexPointer(2, GL_FLOAT, sizeof(a), a.get_address());
255  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
256 
258 
261  }
262 
264  assert(false);
265  }
266 
271  }
272 #endif
273 
274 #ifndef DISABLE_DX9
276  assert(false);
277  }
278 #endif
279 
280 }
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex2f.cpp:101
Vertex2f_Texture()
Initialize the Vertex2f_Texture.
Definition: Vertex2f.cpp:192
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
virtual ~Vertex2f()
Definition: Vertex2f.cpp:61
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex2f.cpp:213
#define GL_VERTEX_ARRAY
Definition: glew_head.h:723
GLuint color
Definition: glew.h:7185
#define GL_LINES
Definition: gl2.h:55
An Abstraction of a Vertex in 2-space, colored.
Definition: Vertex2f.h:80
Point3f position
Definition: Vertex2f.h:77
EGLSurface EGLint x
Definition: eglext.h:293
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
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
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
#define assert(x)
Definition: SDL_malloc.c:1234
#define GL_TRIANGLE_FAN
Definition: gl2.h:60
#define glVertex2f
Definition: gl_mangle.h:1936
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex2f.cpp:90
void * get_address() const
A bit of a hack, necessary to memcpy data into Vertex_Buffers.
Definition: Vertex2f.hxx:25
A 3D Point represented with floats.
Definition: Coordinate.h:133
#define GL_COLOR_ARRAY
Definition: glew_head.h:725
#define glColor4ub
Definition: gl_mangle.h:212
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
#define glTexCoord2f
Definition: gl_mangle.h:1692
#define GL_TRIANGLES
Definition: gl2.h:58
khronos_uint8_t GLubyte
Definition: gl2.h:30
The OpenGL Rendering System.
#define GL_POINTS
Definition: gl2.h:54
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
const GLfloat * c
Definition: glew.h:14913
The OpenGL Rendering System.
Vertex2f_Color()
Initialize the Vertex2f_Color.
Definition: Vertex2f.cpp:74
#define GL_TEXTURE_COORD_ARRAY
Definition: glew_head.h:727
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex2f.cpp:217
#define glDisableClientState
Definition: gl_mangle.h:390
#define glTexCoordPointer
Definition: gl_mangle.h:1739
virtual Point3f get_position() const
Definition: Vertex2f.cpp:64
#define glColorPointer
Definition: gl_mangle.h:236
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Triangle.hxx:85
EGLSurface EGLint EGLint y
Definition: eglext.h:293
An Abstraction of a Vertex in 2-space, textured.
Definition: Vertex2f.h:115
#define glEnableClientState
Definition: gl_mangle.h:438
#define GL_UNSIGNED_BYTE
Definition: gl2.h:236
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
GLint GLint GLint GLint z
Definition: gl2ext.h:1214
#define glBegin
Definition: gl_mangle.h:56
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex2f.cpp:208
#define GL_FLOAT
Definition: gl2.h:241
#define glVertexPointer
Definition: gl_mangle.h:2196
#define glEnd
Definition: gl_mangle.h:450
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
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
#define glDrawArrays
Definition: gl_mangle.h:403
Point3f interpolate_to(const float &rhs_part, const Point3f &rhs) const
Definition: Coordinate.cpp:41
A 2D Point represented with floats.
Definition: Coordinate.h:98
Point2f texture_coordinate
Definition: Vertex2f.h:144
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex2f.cpp:95
Color.
Definition: Color.h:41