jubilant-funicular
Vertex.h
1 #ifndef NTA_VERTEX_H_INCLUDED
2 #define NTA_VERTEX_H_INCLUDED
3 
4 #include <GL/glew.h>
5 
6 #include "nta/MyEngine.h"
7 
8 #define NUM_VERTEX_ATTRIBS 4
9 
11 namespace nta {
13  struct VertexAttrib {
14  void setup() const {
15  glVertexAttribPointer(index, size, type, normalized, stride, pointer);
16  }
17 
18  GLuint index;
19  GLint size;
20  GLenum type;
21  GLboolean normalized;
22  GLsizei stride;
23  GLvoid* pointer;
24  };
26  struct Vertex2D {
29  }
31  Vertex2D(crvec2 p) : pos(p), color(glm::vec4(1)), uv(glm::vec2(0)), hasTexture(0.0) {
32  }
34  Vertex2D(crvec2 p, crvec4 c) : pos(p), color(c), uv(glm::vec2(0)), hasTexture(0.0) {
35  }
37  Vertex2D(crvec2 p, crvec4 c, crvec2 u, float t = 1.0) : pos(p), color(c), uv(u), hasTexture(t) {
38  }
40  Vertex2D(crvec4 c, crvec2 u, float t = 1.0) : pos(0), color(c), uv(u), hasTexture(t) {
41  }
43  void setPosition(float x, float y) {
44  pos.x = x;
45  pos.y = y;
46  }
48  void setColor(float r, float g, float b, float a) {
49  color.r = r;
50  color.g = g;
51  color.b = b;
52  color.a = a;
53  }
54  void setColor(crvec3 c) {
55  color.r = c.r;
56  color.g = c.g;
57  color.b = c.b;
58  color.a = 1;
59  }
61  void setUV(float u, float v) {
62  uv.s = u;
63  uv.t = v;
64  }
66  glm::vec2 pos;
67  glm::vec4 color;
68  glm::vec2 uv;
69  float hasTexture;
70 
71  static const VertexAttrib attribs[NUM_VERTEX_ATTRIBS];
72  };
73 }
74 
75 #endif // NTA_VERTEX_H_INCLUDED
nta::Vertex2D::Vertex2D
Vertex2D()
Initializes an "empty" vertex.
Definition: Vertex.h:28
nta::Vertex2D::Vertex2D
Vertex2D(crvec2 p)
Initializes a white, textureless vertex with given position.
Definition: Vertex.h:31
nta::Vertex2D::Vertex2D
Vertex2D(crvec2 p, crvec4 c)
Initializes textureless, colorful vertex.
Definition: Vertex.h:34
nta::VertexAttrib
represents an attribute of a vertex (e.g. a call to glVertexAttribPointer)
Definition: Vertex.h:13
nta::Vertex2D::Vertex2D
Vertex2D(crvec4 c, crvec2 u, float t=1.0)
Initializes vertex with everything except position.
Definition: Vertex.h:40
nta
Definition: Animation2D.h:6
nta::Vertex2D::setColor
void setColor(float r, float g, float b, float a)
sets the color of the vertex
Definition: Vertex.h:48
nta::Vertex2D
represents a vertex in 2 dimensions
Definition: Vertex.h:26
nta::Vertex2D::pos
glm::vec2 pos
the vertex's position, color, and uv coordinates, respectively
Definition: Vertex.h:66
nta::Vertex2D::Vertex2D
Vertex2D(crvec2 p, crvec4 c, crvec2 u, float t=1.0)
Initializes a vertex with everything.
Definition: Vertex.h:37
nta::Vertex2D::setPosition
void setPosition(float x, float y)
sets the position of the vertex
Definition: Vertex.h:43
nta::Vertex2D::setUV
void setUV(float u, float v)
sets the uv coordinates of the vertex
Definition: Vertex.h:61