xoreos  0.0.5
meshfont.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 
27 namespace Graphics {
28 
29 namespace Mesh {
30 
31 MeshFont::MeshFont() : Mesh(GL_QUADS, GL_DYNAMIC_DRAW) {
32  // Each vertex is { x, y, z, u, v, r, g, b, a }
33  _vertexBuffer.setSize(4, 9 * sizeof(float));
34 
35  VertexDecl vertexDecl;
36  vertexDecl.push_back(VertexAttrib(VPOSITION, 3, GL_FLOAT));
37  vertexDecl.push_back(VertexAttrib(VTCOORD, 2, GL_FLOAT));
38  vertexDecl.push_back(VertexAttrib(VCOLOR, 4, GL_FLOAT));
39  _vertexBuffer.setVertexDeclLinear(4, vertexDecl);
40 
41  // Fill in some valid data so that mesh init doesn't go beserk.
42  float *verts = static_cast<float *>(_vertexBuffer.getData());
43 
44  // Position Data.
45  *verts++ = -1.0f;
46  *verts++ = 0.0f;
47  *verts++ = 0.0f;
48 
49  *verts++ = 0.0f;
50  *verts++ = 1.0f;
51  *verts++ = 0.0f;
52 
53  *verts++ = 1.0f;
54  *verts++ = 1.0f;
55  *verts++ = 0.0f;
56 
57  *verts++ = 1.0f;
58  *verts++ = 0.0f;
59  *verts++ = 0.0f;
60 
61  // UV coordinates.
62  *verts++ = 0.0f;
63  *verts++ = 0.0f;
64 
65  *verts++ = 0.0f;
66  *verts++ = 1.0f;
67 
68  *verts++ = 1.0f;
69  *verts++ = 1.0f;
70 
71  *verts++ = 1.0f;
72  *verts++ = 0.0f;
73 
74  // Colour information.
75  *verts++ = 1.0f;
76  *verts++ = 1.0f;
77  *verts++ = 1.0f;
78  *verts++ = 1.0f;
79 
80  *verts++ = 1.0f;
81  *verts++ = 1.0f;
82  *verts++ = 1.0f;
83  *verts++ = 1.0f;
84 
85  *verts++ = 1.0f;
86  *verts++ = 1.0f;
87  *verts++ = 1.0f;
88  *verts++ = 1.0f;
89 
90  *verts++ = 1.0f;
91  *verts++ = 1.0f;
92  *verts++ = 1.0f;
93  *verts++ = 1.0f;
94 }
95 
96 void MeshFont::render(float *pos, float *uv, float *rgba) {
115  float *verts = static_cast<float *>(_vertexBuffer.getData());
116  for (uint32 i = 0; i < 12; ++i) {
117  verts[i] = pos[i];
118  }
119  for (uint32 i = 0; i < 8; ++i) {
120  verts[i+12] = uv[i];
121  }
122  for (uint32 i = 0; i < 16; ++i) {
123  verts[i+20] = rgba[i];
124  }
126  glDrawArrays(_type, 0, _vertexBuffer.getCount());
127 }
128 
129 } // End of namespace Mesh
130 
131 } // End of namespace Graphics
GLuint _type
Definition: mesh.h:90
Vertex texture coordinates, VTCOORDi = VTCOORD + i.
Definition: vertexbuffer.h:39
Dedicated mesh used for dynamic font rendering.
uint32 getCount() const
Get vertex count.
Vertex position.
Definition: vertexbuffer.h:36
Vertex color.
Definition: vertexbuffer.h:38
void updateGLBound() const
Update an existing GL buffer object, assuming it is already bound.
std::vector< VertexAttrib > VertexDecl
Vertex data layout.
Definition: vertexbuffer.h:63
void setVertexDeclLinear(uint32 vertCount, VertexDecl &decl)
Set the linear vertex declaration for this buffer.
VertexBuffer _vertexBuffer
Definition: mesh.h:81
uint32_t uint32
Definition: types.h:204
GLvoid * getData()
Access buffer data.
Generic vertex attribute data.
Definition: vertexbuffer.h:43
void setSize(uint32 vertCount, uint32 vertSize)
Change buffer size.