zenilib  0.5.3.0
 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 
53  {
54  }
55 
56  Vertex3f::Vertex3f(const Point3f &position, const Point3f &normal)
57  : position(position),
58  normal(normal)
59  {
60  }
61 
63  }
64 
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 
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 
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
110  subrender_to(screen);
111  glEnd();
112  }
113 
115  glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
116  GLubyte((m_argb >> 8) & 0xFF),
117  GLubyte(m_argb & 0xFF),
118  GLubyte((m_argb >> 24) & 0xFF));
121  }
122 #endif
123 
124 #ifndef DISABLE_GL_SHADER
125  template <>
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 
131  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
133  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
134 
135  glDrawArrays(GL_LINES, 0, 2);
136 
139  }
140 
141  template <>
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 
148  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
150  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
151 
152  glDrawArrays(GL_TRIANGLES, 0, 3);
153 
156  }
157 
158  template <>
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 
166  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
168  glColorPointer(4, GL_UNSIGNED_BYTE, 0, c4ub);
169 
171 
174  }
175 
177  Uint32 c4ub = ((m_argb & 0x000000FF) << 16) | ((m_argb & 0x00FF0000) >> 16) | ((m_argb & 0xFF00FF00));
178 
182  glColorPointer(4, GL_UNSIGNED_BYTE, 0, &c4ub);
183 
184  glDrawArrays(GL_POINTS, 0, 1);
185 
188  }
189 
192  glColor4ub(GLubyte((m_argb >> 16) & 0xFF),
193  GLubyte((m_argb >> 8) & 0xFF),
194  GLubyte(m_argb & 0xFF),
195  GLubyte((m_argb >> 24) & 0xFF));
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 
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),
227  }
228 
229  bool Vertex3f_Texture::is_3d() const {
230  return true;
231  }
232 
233 #ifndef DISABLE_GL_FIXED
235  assert(false);
236  }
237 
242  }
243 #endif
244 
245 #ifndef DISABLE_GL_SHADER
246  template <>
249  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
251  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
252 
253  glDrawArrays(GL_LINES, 0, 2);
254 
257  }
258 
259  template <>
262  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
264  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
265 
266  glDrawArrays(GL_TRIANGLES, 0, 3);
267 
270  }
271 
272  template <>
275  glVertexPointer(3, GL_FLOAT, sizeof(a), a.get_address());
277  glTexCoordPointer(2, GL_FLOAT, sizeof(a), &a.texture_coordinate);
278 
280 
283  }
284 
286  assert(false);
287  }
288 
294  }
295 #endif
296 
297 #ifndef DISABLE_DX9
299  assert(false);
300  }
301 #endif
302 
303 }
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex3f.cpp:114
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
#define GL_VERTEX_ARRAY
Definition: glew_head.h:723
GLuint color
Definition: glew.h:7185
#define GL_LINES
Definition: gl2.h:55
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex3f.cpp:108
An Abstraction of a Vertex in 3-space, colored.
Definition: Vertex3f.h:76
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
virtual void subrender_to(Video_GL_Fixed &screen) const
Definition: Vertex3f.cpp:238
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Vertex3f_Texture()
Initialize the Vertex3f_Texture.
Definition: Vertex3f.cpp:207
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:8736
An Abstraction of a Vertex in 3-space, textured.
Definition: Vertex3f.h:113
return Display return Display Bool Bool int d
Definition: SDL_x11sym.h:30
#define assert(x)
Definition: SDL_malloc.c:1234
Point3f position
Definition: Vertex3f.h:72
#define GL_TRIANGLE_FAN
Definition: gl2.h:60
Point2f texture_coordinate
Definition: Vertex3f.h:143
void * get_address() const
A bit of a hack, necessary to memcpy data into Vertex_Buffers.
Definition: Vertex3f.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 glVertex3f
Definition: gl_mangle.h:1946
#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.
virtual Point3f get_position() const
Definition: Vertex3f.cpp:65
#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
#define glNormal3f
Definition: gl_mangle.h:1224
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
The OpenGL Rendering System.
#define GL_TEXTURE_COORD_ARRAY
Definition: glew_head.h:727
#define glDisableClientState
Definition: gl_mangle.h:390
#define glTexCoordPointer
Definition: gl_mangle.h:1739
#define glColorPointer
Definition: gl_mangle.h:236
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Triangle.hxx:85
virtual ~Vertex3f()
Definition: Vertex3f.cpp:62
#define glEnableClientState
Definition: gl_mangle.h:438
#define GL_UNSIGNED_BYTE
Definition: gl2.h:236
virtual void render_to(Video_GL_Fixed &screen) const
Overridden for OpenGL rendering.
Definition: Vertex3f.cpp:234
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
GLdouble GLdouble GLdouble b
Definition: glew.h:8383
#define glBegin
Definition: gl_mangle.h:56
#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
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex3f.cpp:229
Point3f normal
Definition: Vertex3f.h:73
#define glDrawArrays
Definition: gl_mangle.h:403
Point3f interpolate_to(const float &rhs_part, const Point3f &rhs) const
Definition: Coordinate.cpp:41
Uint32 get_argb() const
Get a Uint32 representation of 0xAARRGGBB.
Definition: Color.hxx:47
A 2D Point represented with floats.
Definition: Coordinate.h:98
Vertex3f_Color()
Initialize the Vertex3f_Color.
Definition: Vertex3f.cpp:75
virtual bool is_3d() const
Tell the rendering system if we&#39;re using 3D coordinates.
Definition: Vertex3f.cpp:103
Color.
Definition: Color.h:41