MVE - Multi-View Environment mve-devel
Loading...
Searching...
No Matches
render_tools.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015, Simon Fuhrmann
3 * TU Darmstadt - Graphics, Capture and Massively Parallel Computing
4 * All rights reserved.
5 *
6 * This software may be modified and distributed under the terms
7 * of the BSD 3-Clause license. See the LICENSE.txt file for details.
8 */
9
10#include "mve/mesh.h"
11#include "ogl/mesh_renderer.h"
12#include "ogl/render_tools.h"
13
15
16VertexArray::Ptr
18{
19 /* Create the mesh. */
21 mve::TriangleMesh::VertexList& verts(mesh->get_vertices());
22 mve::TriangleMesh::FaceList& faces(mesh->get_faces());
23 mve::TriangleMesh::ColorList& colors(mesh->get_vertex_colors());
24
25 for (int hs = 0; hs < 2; ++hs)
26 for (int i = 0; i < 3; ++i) // For each axis
27 {
28 float axis[4] =
29 {
30 i == 0 ? 1.0f : 0.0f,
31 i == 1 ? 1.0f : 0.0f,
32 i == 2 ? 1.0f : 0.0f,
33 1.0f
34 };
35
36 math::Vec4f color(axis);
37 color = color * (hs == 0 ? 1.0f : 0.2f);
38 color[3] = 1.0f;
39
40 float sign = (hs == 0 ? 1.0f : -1.0f);
41 for (int i = 0; i < 3; ++i) axis[i] *= sign;
42
43 verts.push_back(math::Vec3f(0.0f, 0.0f, 0.0f));
44 verts.push_back(math::Vec3f(axis[0] * 100.0f, axis[1] * 100.0f, axis[2] * 100.0f));
45 faces.push_back(verts.size() - 2);
46 faces.push_back(verts.size() - 1);
47 colors.push_back(color);
48 colors.push_back(color);
49
50 for (float j = 1.0f; j < 10.0f; j += 1.0f)
51 {
52 for (float scale = 0.01f; scale < 15.0f; scale *= 10.0f)
53 {
54 verts.push_back(math::Vec3f
55 (axis[0] * j + axis[1] * 0.1f + axis[2] * 0.1f,
56 axis[1] * j + axis[0] * 0.1f, axis[2] * j) * scale);
57 verts.push_back(math::Vec3f
58 (axis[0] * j + axis[1] * -0.1f + axis[2] * -0.1f,
59 axis[1] * j + axis[0] * -0.1f, axis[2] * j) * scale);
60 faces.push_back(verts.size() - 2);
61 faces.push_back(verts.size() - 1);
62 colors.push_back(color);
63 colors.push_back(color);
64
65 verts.push_back(math::Vec3f
66 (axis[0] * j, axis[1] * j + axis[2] * 0.1f,
67 axis[2] * j + axis[0] * 0.1f + axis[1] * 0.1f) * scale);
68 verts.push_back(math::Vec3f
69 (axis[0] * j, axis[1] * j + axis[2] * -0.1f,
70 axis[2] * j + axis[0] * -0.1f + axis[1] * -0.1f) * scale);
71 faces.push_back(verts.size() - 2);
72 faces.push_back(verts.size() - 1);
73 colors.push_back(color);
74 colors.push_back(color);
75 }
76 }
77 }
78
79 /* Generate the renderer. */
80 MeshRenderer::Ptr ret(MeshRenderer::create());
81 ret->set_primitive(GL_LINES);
82 ret->set_shader(shader);
83 ret->set_mesh(mesh);
84
85 return ret;
86}
87
88/* ---------------------------------------------------------------- */
89
90VertexArray::Ptr
92{
94 mve::TriangleMesh::VertexList& verts(mesh->get_vertices());
95 mve::TriangleMesh::NormalList& vnormals(mesh->get_vertex_normals());
96 mve::TriangleMesh::TexCoordList& vtexuv(mesh->get_vertex_texcoords());
97
98 verts.push_back(math::Vec3f(-1.0f, 1.0f, 0.0f));
99 verts.push_back(math::Vec3f(-1.0f, -1.0f, 0.0f));
100 verts.push_back(math::Vec3f(1.0f, 1.0f, 0.0f));
101 verts.push_back(math::Vec3f(1.0f, -1.0f, 0.0f));
102 vnormals.push_back(math::Vec3f(0.0f, 0.0f, 1.0f));
103 vnormals.push_back(math::Vec3f(0.0f, 0.0f, 1.0f));
104 vnormals.push_back(math::Vec3f(0.0f, 0.0f, 1.0f));
105 vnormals.push_back(math::Vec3f(0.0f, 0.0f, 1.0f));
106 vtexuv.push_back(math::Vec2f(0.0f, 0.0f));
107 vtexuv.push_back(math::Vec2f(0.0f, 1.0f));
108 vtexuv.push_back(math::Vec2f(1.0f, 0.0f));
109 vtexuv.push_back(math::Vec2f(1.0f, 1.0f));
110
111 /* Generate the renderer. */
112 MeshRenderer::Ptr ret(MeshRenderer::create());
113 ret->set_primitive(GL_TRIANGLE_STRIP);
114 ret->set_shader(shader);
115 ret->set_mesh(mesh);
116 return ret;
117}
118
Vector class for arbitrary dimensions and types.
Definition vector.h:87
std::vector< math::Vec3f > VertexList
Definition mesh.h:33
std::vector< math::Vec4f > ColorList
Definition mesh.h:34
std::vector< math::Vec3f > NormalList
Definition mesh.h:95
std::vector< math::Vec2f > TexCoordList
Definition mesh.h:96
std::shared_ptr< TriangleMesh > Ptr
Definition mesh.h:92
std::vector< VertexID > FaceList
Definition mesh.h:97
static Ptr create(void)
Definition mesh.h:295
std::shared_ptr< MeshRenderer > Ptr
std::shared_ptr< ShaderProgram > Ptr
VertexArray::Ptr create_axis_renderer(ShaderProgram::Ptr shader)
Generates a vertex array for visualizing the three world coordinate axis.
VertexArray::Ptr create_fullscreen_quad(ShaderProgram::Ptr shader)
Generates a full screen quad renderer in OpenGL unit coordinates.
#define OGL_NAMESPACE_END
Definition defines.h:14
#define OGL_NAMESPACE_BEGIN
Definition defines.h:13