Mesh

struct glen::Mesh

Raw mesh type.

Vertices define the points that make up the mesh. Indices should be provided in sets of three and define to connect the points with triangular faces.

Public Types

typedef std::vector<Vertex> vertices_type
typedef GLushort index_type
typedef std::vector<index_type> indices_type
typedef std::vector<Vertex>::const_iterator vrt_iterator
typedef std::vector<GLushort>::const_iterator ind_iterator

Public Functions

Mesh()

Constructor.

Mesh(std::shared_ptr<vertices_type> vertices, std::shared_ptr<indices_type> indices)

Constructor.

Parameters
  • vertices: The vertices that will make up the mesh

  • indices: The indices that will be used to specify the triangles of the mesh

Mesh(const Mesh&) = delete

Use move constructor instead of copy constructor.

Mesh(Mesh &&other) = default

Move constructor.

Mesh &operator=(const Mesh&) = delete

Use move assign instead of copy assign.

Mesh &operator=(Mesh &&other) = default

Move assign.

~Mesh()

destructor

Mesh &operator+=(Mesh &other)

Combine this mesh with another mesh.

Return

The combined mesh

Parameters
  • other: The other mesh

void append_vertex(const Vertex vertex)

Parameters
  • vertex: The vertex to add

void append_triangle(const Vertex vertex_1, const Vertex vertex_2, const Vertex vertex_3)

Add three vertices. Indices will need to be set up seperately.

void append_index(const GLushort index)

Add a single index to a specify an existing vertex as part of a triangle.

This should be called in groups of three in order to add whole triangles.

Parameters

void transform(glm::mat4 transformMatrix)

Move all vertices in mesh according to transformMatrix.

void scale_uvs(const GLfloat amount)

Scale all UVs evenly. Useful for making use of tiled textures.

void reverse_triangles()

Reverse the facing direction of all triangles in the mesh by reversing the winding direction.

void make_indices_smooth()

Interpolate normals so faces appear smooth.

void make_indices_faceted()

Don’t interpolate normals. All faces will appear flat.

void make_tangents()

Automatically make all tangents and bitangents for mesh.

Properly set up tangents are required proper display.

Vertex *get_vertex(std::size_t loc)

Return

The vertex at index: loc.

index_type get_index(std::size_t loc)

Return

Vertex index located at loc in index array.

std::size_t num_indices()

Return

The number of indices.

std::size_t num_vertices()

Return

The number of vertices.

std::shared_ptr<vertices_type> vertices()

Return

Pointer to all vertices in the mesh.

const std::shared_ptr<indices_type> &indices() const

Return

Pointer to all indices in the mesh.

const GLuint id() const

Return

Unique ID for this mesh.

GLsizeiptr size_vertices()

Return

The size in bytes of all vertices in the mesh.

GLsizeiptr size_indices()

Return

The size in bytes of all indices in the mesh.

GLsizeiptr size_shape()

Return

The size in bytes of all indices and vertices in the mesh.

void set_vertex(std::size_t loc, Vertex &data)

Set vertex at index loc to be data.

void set_vertex_position(GLuint loc, glm::vec3 position)

Set vertex’s coordinates at index loc to position.

void set_index(std::size_t loc, const index_type &data)

Set index at index array position loc to be data.

void set_id(GLuint s_id)
vrt_iterator vert_begin()

Return

Iterator to start of vertices.

vrt_iterator vert_end()

Return

Iterater to end of veritces.

ind_iterator indx_begin()

Return

Iterator to start of indices.

ind_iterator indx_end()

Return

Iterator to end of indies.

OBJ Loader

struct glen::OBJ_Loader

OBJ Loader. At the moment, the obj files have to be in triangulated form.

Public Static Functions

Mesh load_obj(const char *path)

Return

The new mesh

Parameters
  • path: The path to the OBJ file

Arrow

struct glen::Arrow

Basic 3D arrow shape.

Public Static Functions

Mesh create_arrow()

Return

3D arrow mesh.

Mesh create_arrow(const float length)

Return

3D arrow mesh.

Parameters
  • length: The length of the tail.

Cube

struct glen::Cube

Basic cube.

Public Static Functions

Mesh create_cube()

Default cube mesh.

Return

A cube that goes from -1 to 1 in x, y and z.

Mesh create_cube(const float width, const bool is_default = false)

Return

A cube mesh that sits on the ground plane

Parameters
  • width: The width of all sides of the cube

Cylinder

struct glen::Cylinder

Basic cylinder with cap.

Public Static Functions

Mesh create_cylinder()

Return

Default cylinder mesh with radius: 0.5, height: 2 and 24 faces around the side.

Mesh create_cylinder(const float radius, const float height)

Return

A cylinder mesh with given radius and height and 24 faces around the side.

Parameters
  • radius: The radius of the cylinder.

  • height: The height of the cylinder.

Mesh create_cylinder(const float radius, const float height, const uint16_t width_segments, const uint16_t height_segments)

Return

Parameters
  • radius: The radius of the cylinder.

  • height: The height of the cylinder.

  • width_segments: The number of edges around the side. A higher number will result in a smoother cylinder.

  • height_segments: The number of subdivisions going up the height of the cylinder. This will not affect the smoothness of the cylinder.

Plane

struct glen::Plane

Basic plane

Public Static Functions

Mesh create_plane()

Return

A new 1 x 1 plane

Mesh create_plane(const float width, const float height)

Return

A new plane of size width x height.

Mesh create_plane(const float width, const float height, const uint16_t width_segments, const uint16_t height_segments)

Return

A new plane of size width x height, with width_segments edges making up the width and height_segments edges making up the height.

Sphere

struct glen::Sphere

Basic sphere

Public Static Functions

Mesh create_sphere(const float radius)

Return

Sphere mesh of radius radius.

Mesh create_sphere(const float radius, const uint16_t segments)

Return

Sphere mesh with radius radius and segments edges around and segments/2 edges high. This ratio generally looks even.

Mesh create_sphere(const float radius, const uint16_t width_segments, const uint16_t height_segments)

Return

Sphere mesh with radius radius and width_segments edges around and height_segments edges high.

Window Quad

struct glen::WindowQuad

Mesh for rendering a 2D image directly to the window

Public Static Functions

Mesh create_windowQuad()

Return

Window plane mesh