21 #if MRPT_HAS_OPENGL_GLUT 24 const char* vertex_shader =
nullptr;
25 const char* fragment_shader =
nullptr;
26 std::vector<std::string> attribs, uniforms;
32 #include "../shaders/points.v.glsl" 35 #include "../shaders/points.f.glsl" 37 uniforms = {
"p_matrix",
40 "enableVariablePointSize",
41 "variablePointSize_K",
42 "variablePointSize_DepthScale"};
43 attribs = {
"position",
"vertexColor"};
49 #include "../shaders/wireframe.v.glsl" 52 #include "../shaders/wireframe.f.glsl" 54 uniforms = {
"p_matrix",
"mv_matrix"};
55 attribs = {
"position",
"vertexColor"};
61 #include "../shaders/triangles.v.glsl" 64 #include "../shaders/triangles.f.glsl" 66 uniforms = {
"p_matrix",
"mv_matrix",
"light_diffuse",
67 "light_ambient",
"light_specular",
"light_direction"};
68 attribs = {
"position",
"vertexColor",
"vertexNormal"};
73 #include "../shaders/textured-triangles.v.glsl" 76 #include "../shaders/textured-triangles.f.glsl" 78 uniforms = {
"p_matrix",
"mv_matrix",
"pmv_matrix",
79 "light_diffuse",
"light_ambient",
"light_specular",
80 "light_direction",
"textureSampler",
"enableLight"};
81 attribs = {
"position",
"vertexUV",
"vertexNormal"};
86 #include "../shaders/text.v.glsl" 89 #include "../shaders/text.f.glsl" 91 uniforms = {
"p_matrix",
"mv_matrix"};
92 attribs = {
"position",
"vertexColor"};
97 "Unknown shader_id_t=%u", static_cast<unsigned>(
id));
105 auto shader = std::make_shared<Program>();
108 std::vector<Shader> lstShaders;
109 lstShaders.resize(2);
110 if (!lstShaders[0].compile(GL_VERTEX_SHADER, vertex_shader, errMsgs))
113 "Error compiling GL_VERTEX_SHADER:\n%s", errMsgs.c_str());
115 if (!lstShaders[1].compile(GL_FRAGMENT_SHADER, fragment_shader, errMsgs))
118 "Error compiling GL_FRAGMENT_SHADER:\n%s", errMsgs.c_str());
120 if (!shader->linkProgram(lstShaders, errMsgs))
123 "Error linking Opengl Shader programs:\n%s", errMsgs.c_str());
128 std::cout <<
"Built Shader program #" << int(
id) <<
"\n";
129 shader->dumpProgramDescription(std::cout);
134 for (
const auto& name : uniforms) shader->declareUniform(name);
137 for (
const auto& name : attribs) shader->declareAttribute(name);
static constexpr shader_id_t TEXTURED_TRIANGLES
#define THROW_EXCEPTION(msg)
static constexpr shader_id_t TEXT
static constexpr shader_id_t WIREFRAME
uint8_t shader_id_t
Type for IDs of shaders.
static constexpr shader_id_t TRIANGLES
Program::Ptr LoadDefaultShader(const shader_id_t id)
Loads a set of OpenGL Vertex+Fragment shaders from the default library available in mrpt::opengl...
The namespace for 3D scene representation and rendering.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
static constexpr shader_id_t POINTS