21 #if MRPT_HAS_OPENGL_GLUT 23 #if defined(MRPT_OS_LINUX) 26 if (!::getenv(
"MESA_GL_VERSION_OVERRIDE"))
28 ::putenv(
"MESA_GL_VERSION_OVERRIDE=3.3");
33 const char* vertex_shader =
nullptr;
34 const char* fragment_shader =
nullptr;
35 std::vector<std::string> attribs, uniforms;
41 #include "../shaders/points.v.glsl" 44 #include "../shaders/points.f.glsl" 46 uniforms = {
"p_matrix",
49 "enableVariablePointSize",
50 "variablePointSize_K",
51 "variablePointSize_DepthScale"};
52 attribs = {
"position",
"vertexColor"};
58 #include "../shaders/wireframe.v.glsl" 61 #include "../shaders/wireframe.f.glsl" 63 uniforms = {
"p_matrix",
"mv_matrix"};
64 attribs = {
"position",
"vertexColor"};
70 #include "../shaders/triangles.v.glsl" 73 #include "../shaders/triangles.f.glsl" 75 uniforms = {
"p_matrix",
"mv_matrix",
"light_diffuse",
76 "light_ambient",
"light_specular",
"light_direction"};
77 attribs = {
"position",
"vertexColor",
"vertexNormal"};
82 #include "../shaders/textured-triangles.v.glsl" 85 #include "../shaders/textured-triangles.f.glsl" 87 uniforms = {
"p_matrix",
"mv_matrix",
"pmv_matrix",
88 "light_diffuse",
"light_ambient",
"light_specular",
89 "light_direction",
"textureSampler",
"enableLight"};
90 attribs = {
"position",
"vertexUV",
"vertexNormal"};
95 #include "../shaders/text.v.glsl" 98 #include "../shaders/text.f.glsl" 100 uniforms = {
"p_matrix",
"mv_matrix"};
101 attribs = {
"position",
"vertexColor"};
106 "Unknown shader_id_t=%u", static_cast<unsigned>(
id));
114 auto shader = std::make_shared<Program>();
117 std::vector<Shader> lstShaders;
118 lstShaders.resize(2);
119 if (!lstShaders[0].compile(GL_VERTEX_SHADER, vertex_shader, errMsgs))
122 "Error compiling GL_VERTEX_SHADER:\n%s", errMsgs.c_str());
124 if (!lstShaders[1].compile(GL_FRAGMENT_SHADER, fragment_shader, errMsgs))
127 "Error compiling GL_FRAGMENT_SHADER:\n%s", errMsgs.c_str());
129 if (!shader->linkProgram(lstShaders, errMsgs))
132 "Error linking Opengl Shader programs:\n%s", errMsgs.c_str());
137 std::cout <<
"Built Shader program #" << int(
id) <<
"\n";
138 shader->dumpProgramDescription(std::cout);
143 for (
const auto& name : uniforms) shader->declareUniform(name);
146 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