22 #if MRPT_HAS_OPENGL_GLUT 24 #if defined(MRPT_OS_LINUX) 27 if (!::getenv(
"MESA_GL_VERSION_OVERRIDE"))
29 std::string s =
"MESA_GL_VERSION_OVERRIDE=3.3";
35 const char* vertex_shader =
nullptr;
36 const char* fragment_shader =
nullptr;
37 std::vector<std::string> attribs, uniforms;
43 #include "../shaders/points.v.glsl" 46 #include "../shaders/points.f.glsl" 52 "enableVariablePointSize",
53 "variablePointSize_K",
54 "variablePointSize_DepthScale"};
55 attribs = {
"position",
"vertexColor"};
61 #include "../shaders/wireframe.v.glsl" 64 #include "../shaders/wireframe.f.glsl" 66 uniforms = {
"p_matrix",
"mv_matrix"};
67 attribs = {
"position",
"vertexColor"};
73 #include "../shaders/triangles.v.glsl" 76 #include "../shaders/triangles.f.glsl" 78 uniforms = {
"p_matrix",
"mv_matrix",
"light_diffuse",
79 "light_ambient",
"light_specular",
"light_direction"};
80 attribs = {
"position",
"vertexColor",
"vertexNormal"};
85 #include "../shaders/textured-triangles.v.glsl" 88 #include "../shaders/textured-triangles.f.glsl" 90 uniforms = {
"p_matrix",
"mv_matrix",
"pmv_matrix",
91 "light_diffuse",
"light_ambient",
"light_specular",
92 "light_direction",
"textureSampler",
"enableLight"};
93 attribs = {
"position",
"vertexUV",
"vertexNormal"};
98 #include "../shaders/text.v.glsl" 101 #include "../shaders/text.f.glsl" 103 uniforms = {
"p_matrix",
"mv_matrix"};
104 attribs = {
"position",
"vertexColor"};
109 "Unknown shader_id_t=%u", static_cast<unsigned>(
id));
117 auto shader = std::make_shared<Program>();
120 std::vector<Shader> lstShaders;
121 lstShaders.resize(2);
122 if (!lstShaders[0].compile(GL_VERTEX_SHADER, vertex_shader, errMsgs))
125 "Error compiling GL_VERTEX_SHADER:\n%s", errMsgs.c_str());
127 if (!lstShaders[1].compile(GL_FRAGMENT_SHADER, fragment_shader, errMsgs))
130 "Error compiling GL_FRAGMENT_SHADER:\n%s", errMsgs.c_str());
132 if (!shader->linkProgram(lstShaders, errMsgs))
135 "Error linking Opengl Shader programs:\n%s", errMsgs.c_str());
140 std::cout <<
"Built Shader program #" << int(
id) <<
"\n";
141 shader->dumpProgramDescription(std::cout);
146 for (
const auto& name : uniforms) shader->declareUniform(name);
149 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