libigl v2.5.0
Loading...
Searching...
No Matches
igl::opengl Namespace Reference

Namespaces

namespace  glfw
 
namespace  stb
 

Classes

struct  gliGenericImage
 
class  MeshGL
 Coverts mesh data inside a igl::ViewerData class in an OpenGL compatible format The class includes a shader and the opengl calls to plot the data. More...
 
struct  TgaFooter
 
struct  TgaHeader
 
class  ViewerCore
 Basic class of the 3D mesh viewer. More...
 
class  ViewerData
 Object being drawn (i.e., mesh and its accessories) by the ViewerCore. More...
 

Functions

bool render_to_tga (const std::string tga_file, const int width, const int height, const bool alpha)
 alpha whether to include alpha channel
 
bool texture_from_tga (const std::string tga_file, GLuint &id)
 Read an image from a .tga file and use it as a texture.
 
gliGenericImagegliReadTGA (FILE *fp, char *name, int hflip, int vflip)
 
int gli_verbose (int new_verbose)
 
int gliVerbose (int newVerbose)
 
void writeTGA (gliGenericImage *image, FILE *fp)
 
template<typename Scalar , int RowsAtCompileTime, int ColsAtCompileTime>
GLint bind_vertex_attrib_array (const GLuint program_shader, const std::string &name, GLuint bufferID, const Eigen::Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, Eigen::RowMajor > &M, const bool refresh)
 Bind a per-vertex array attribute and refresh its contents from an Eigen matrix.
 
void create_index_vbo (const Eigen::MatrixXi &F, GLuint &F_vbo_id)
 Create a VBO (Vertex Buffer Object) for a list of indices: GL_ELEMENT_ARRAY_BUFFER_ARB for the triangle indices (F)
 
void create_mesh_vbo (const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, GLuint &V_vbo_id, GLuint &F_vbo_id)
 Create a VBO (Vertex Buffer Object) for a mesh.
 
void create_mesh_vbo (const Eigen::MatrixXd &V, const Eigen::MatrixXi &F, const Eigen::MatrixXd &N, GLuint &V_vbo_id, GLuint &F_vbo_id, GLuint &N_vbo_id)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool create_shader_program (const std::string &geom_source, const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib, GLuint &id)
 Create a shader program with a vertex and fragments shader loading from source strings and vertex attributes assigned from a map before linking the shaders to the program, making it ready to use with glUseProgram(id)
 
bool create_shader_program (const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib, GLuint &id)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
GLuint create_shader_program (const std::string &geom_source, const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
GLuint create_shader_program (const std::string &vert_source, const std::string &frag_source, const std::map< std::string, GLuint > &attrib)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
void create_vector_vbo (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &V, GLuint &V_vbo_id)
 Create a VBO (Vertex Buffer Object) for a list of vectors: GL_ARRAY_BUFFER for the vectors (V)
 
bool destroy_shader_program (const GLuint id)
 Properly destroy a shader program.
 
int gl_type_size (const GLenum type)
 Return the number of bytes for a given OpenGL type.
 
void init_render_to_texture (const size_t width, const size_t height, const bool depth_texture, GLuint &tex_id, GLuint &fbo_id, GLuint &d_id)
 Create a frame buffer that renders color to a RGBA texture a depth to a "render buffer".
 
void init_render_to_texture (const size_t width, const size_t height, GLuint &tex_id, GLuint &fbo_id, GLuint &dfbo_id)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
GLuint load_shader (const std::string &src, const GLenum type)
 Creates and compiles a shader from a given string.
 
void print_program_info_log (const GLuint obj)
 Print the information log for a program object.
 
void print_shader_info_log (const GLuint obj)
 Print the info log for a shader object.
 
template<typename T >
void read_pixels (const GLuint width, const GLuint height, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &R, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &G, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &B, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &A, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &D)
 Read full viewport into color, alpha and depth arrays suitable for igl::png::writePNG.
 
GLenum report_gl_error (const std::string id)
 Print last OpenGL error to stderr prefixed by specified id string.
 
GLenum report_gl_error ()
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::string uniform_type_to_string (const GLenum type)
 Convert a GL uniform variable type (say, returned from glGetActiveUniform) and output a string naming that type.
 
void decompress_verasansmono_atlas (unsigned char *_fontatlas)
 Decompress the vera sans mono font atlas.
 
template<typename DerivedV , typename DerivedF >
void vertex_array (const Eigen::PlainObjectBase< DerivedV > &V, const Eigen::PlainObjectBase< DerivedF > &F, GLuint &va_id, GLuint &ab_id, GLuint &eab_id)
 Create a GL_VERTEX_ARRAY for a given mesh (V,F)
 

Function Documentation

◆ render_to_tga()

bool igl::opengl::render_to_tga ( const std::string  tga_file,
const int  width,
const int  height,
const bool  alpha 
)

alpha whether to include alpha channel

◆ texture_from_tga()

bool igl::opengl::texture_from_tga ( const std::string  tga_file,
GLuint &  id 
)

Read an image from a .tga file and use it as a texture.

Parameters
[in]tga_filepath to .tga file
[out]idof generated openGL texture
Returns
true on success, false on failure

◆ gliReadTGA()

gliGenericImage * igl::opengl::gliReadTGA ( FILE *  fp,
char *  name,
int  hflip,
int  vflip 
)
extern

◆ gli_verbose()

int igl::opengl::gli_verbose ( int  new_verbose)

◆ gliVerbose()

int igl::opengl::gliVerbose ( int  newVerbose)
extern

◆ writeTGA()

void igl::opengl::writeTGA ( gliGenericImage image,
FILE *  fp 
)

◆ bind_vertex_attrib_array()

template<typename Scalar , int RowsAtCompileTime, int ColsAtCompileTime>
GLint igl::opengl::bind_vertex_attrib_array ( const GLuint  program_shader,
const std::string &  name,
GLuint  bufferID,
const Eigen::Matrix< Scalar, RowsAtCompileTime, ColsAtCompileTime, Eigen::RowMajor > &  M,
const bool  refresh 
)

Bind a per-vertex array attribute and refresh its contents from an Eigen matrix.

Parameters
[in]program_shaderid of shader program
[in]namename of attribute in vertex shader
[in]bufferIDid of buffer to bind to
[in]M#V by dim matrix of per-vertex data
[in]refreshwhether to actually call glBufferData or just bind the buffer
Returns
id of named attribute in shader

◆ create_index_vbo()

void igl::opengl::create_index_vbo ( const Eigen::MatrixXi &  F,
GLuint &  F_vbo_id 
)

Create a VBO (Vertex Buffer Object) for a list of indices: GL_ELEMENT_ARRAY_BUFFER_ARB for the triangle indices (F)

Parameters
[in]F#F by 3 eigen Matrix of face (triangle) indices
[out]F_vbo_idbuffer id for face indices

◆ create_mesh_vbo() [1/2]

void igl::opengl::create_mesh_vbo ( const Eigen::MatrixXd &  V,
const Eigen::MatrixXi &  F,
GLuint &  V_vbo_id,
GLuint &  F_vbo_id 
)

Create a VBO (Vertex Buffer Object) for a mesh.

Actually two VBOs: one GL_ARRAY_BUFFER for the vertex positions (V) and one GL_ELEMENT_ARRAY_BUFFER for the triangle indices (F)

Parameters
[in]V#V by 3 eigen Matrix of mesh vertex 3D positions
[in]F#F by 3 eigen Matrix of face (triangle) indices
[out]V_vbo_idbuffer id for vertex positions
[out]F_vbo_idbuffer id for face indices
Note
when using glDrawElements VBOs for V and F using MatrixXd and MatrixXi will have types GL_DOUBLE and GL_UNSIGNED_INT respectively

◆ create_mesh_vbo() [2/2]

void igl::opengl::create_mesh_vbo ( const Eigen::MatrixXd &  V,
const Eigen::MatrixXi &  F,
const Eigen::MatrixXd &  N,
GLuint &  V_vbo_id,
GLuint &  F_vbo_id,
GLuint &  N_vbo_id 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
[in]N#V by 3 eigen Matrix of mesh vertex 3D normals
[out]N_vbo_idbuffer id for vertex positions

◆ create_shader_program() [1/4]

bool igl::opengl::create_shader_program ( const std::string &  geom_source,
const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib,
GLuint &  id 
)

Create a shader program with a vertex and fragments shader loading from source strings and vertex attributes assigned from a map before linking the shaders to the program, making it ready to use with glUseProgram(id)

Parameters
[in]geom_sourcestring containing source code of geometry shader (can be "" to mean use default pass-through)
[in]vert_sourcestring containing source code of vertex shader
[in]frag_sourcestring containing source code of fragment shader
[in]attribmap containing table of vertex attribute strings add their correspondingly ids (generated previously using glBindAttribLocation)
[out]idindex id of created shader, set to 0 on error
Returns
true on success, false on error
Note
Caller is responsible for making sure that current value of id is not leaking a shader (since it will be overwritten)
See also
destroy_shader_program

◆ create_shader_program() [2/4]

bool igl::opengl::create_shader_program ( const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib,
GLuint &  id 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ create_shader_program() [3/4]

GLuint igl::opengl::create_shader_program ( const std::string &  geom_source,
const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
index id of created shader, set to 0 on error

◆ create_shader_program() [4/4]

GLuint igl::opengl::create_shader_program ( const std::string &  vert_source,
const std::string &  frag_source,
const std::map< std::string, GLuint > &  attrib 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns
index id of created shader, set to 0 on error

◆ create_vector_vbo()

template<typename T >
void igl::opengl::create_vector_vbo ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  V,
GLuint &  V_vbo_id 
)

Create a VBO (Vertex Buffer Object) for a list of vectors: GL_ARRAY_BUFFER for the vectors (V)

Template Parameters
Tshould be a eigen matrix primitive type like int or double
Parameters
[in]Vm by n eigen Matrix of type T values
[out]V_vbo_idbuffer id for vectors

◆ destroy_shader_program()

bool igl::opengl::destroy_shader_program ( const GLuint  id)

Properly destroy a shader program.

Detach and delete each of its shaders and delete it

Parameters
[in]idindex id of created shader, set to 0 on error
Returns
true on success, false on error
Note
caller is responsible for making sure he doesn't foolishly continue to use id as if it still contains a program
See also
create_shader_program

◆ gl_type_size()

int igl::opengl::gl_type_size ( const GLenum  type)

Return the number of bytes for a given OpenGL type.

Parameters
[in]typeenum value of opengl type
Returns
size in bytes of type

◆ init_render_to_texture() [1/2]

void igl::opengl::init_render_to_texture ( const size_t  width,
const size_t  height,
const bool  depth_texture,
GLuint &  tex_id,
GLuint &  fbo_id,
GLuint &  d_id 
)

Create a frame buffer that renders color to a RGBA texture a depth to a "render buffer".

After calling this, you can use with something like:

glBindFramebuffer(GL_FRAMEBUFFER, fbo_id);
if(!depth_texture)
{
glBindRenderbuffer(GL_RENDERBUFFER, d_id);
}
//
// draw scene ...
//
// clean up
glBindFramebuffer(GL_FRAMEBUFFER,0);
if(!depth_texture)
{
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
// Later ...
glActiveTexture(GL_TEXTURE0+0);
glBindTexture(GL_TEXTURE_2D,tex_id);
if(depth_texture)
{
glActiveTexture(GL_TEXTURE0+1);
glBindTexture(GL_TEXTURE_2D,d_id);
}
// draw textures
Parameters
[in]widthimage width
[in]heightimage height
[in]depth_texturewhether to create a texture for depth or to create a render buffer for depth
[out]tex_idid of the texture
[out]fbo_idid of the frame buffer object
[out]d_idid of the depth texture or frame buffer object

◆ init_render_to_texture() [2/2]

void igl::opengl::init_render_to_texture ( const size_t  width,
const size_t  height,
GLuint &  tex_id,
GLuint &  fbo_id,
GLuint &  dfbo_id 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Wrapper with depth_texture = false for legacy reasons

◆ load_shader()

GLuint igl::opengl::load_shader ( const std::string &  src,
const GLenum  type 
)

Creates and compiles a shader from a given string.

Parameters
[in]srcstring containing GLSL shader code
[in]typeGLSL type of shader, one of: GL_VERTEX_SHADER GL_FRAGMENT_SHADER GL_GEOMETRY_SHADER
Returns
index id of the newly created shader, 0 on error

Will immediately return 0 if src is empty.

◆ print_program_info_log()

void igl::opengl::print_program_info_log ( const GLuint  obj)

Print the information log for a program object.

Parameters
[in]objOpenGL index of program to print info log about

◆ print_shader_info_log()

void igl::opengl::print_shader_info_log ( const GLuint  obj)

Print the info log for a shader object.

Parameters
[in]objOpenGL index of shader to print info log about

◆ read_pixels()

template<typename T >
void igl::opengl::read_pixels ( const GLuint  width,
const GLuint  height,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  R,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  G,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  B,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  A,
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  D 
)

Read full viewport into color, alpha and depth arrays suitable for igl::png::writePNG.

Parameters
[in]widthwidth of viewport
[in]heightheight of viewport
[out]Rwidth by height list of red values
[out]Gwidth by height list of green values
[out]Bwidth by height list of blue values
[out]Awidth by height list of alpha values
[out]Dwidth by height list of depth values

◆ report_gl_error() [1/2]

GLenum igl::opengl::report_gl_error ( const std::string  id)

Print last OpenGL error to stderr prefixed by specified id string.

Parameters
[in]idstring to appear before any error msgs
Returns
result of glGetError()

◆ report_gl_error() [2/2]

GLenum igl::opengl::report_gl_error ( )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ uniform_type_to_string()

std::string igl::opengl::uniform_type_to_string ( const GLenum  type)

Convert a GL uniform variable type (say, returned from glGetActiveUniform) and output a string naming that type.

Parameters
[in]typeenum for given type
Returns
string name of that type

◆ decompress_verasansmono_atlas()

void igl::opengl::decompress_verasansmono_atlas ( unsigned char *  _fontatlas)

Decompress the vera sans mono font atlas.

◆ vertex_array()

template<typename DerivedV , typename DerivedF >
void igl::opengl::vertex_array ( const Eigen::PlainObjectBase< DerivedV > &  V,
const Eigen::PlainObjectBase< DerivedF > &  F,
GLuint &  va_id,
GLuint &  ab_id,
GLuint &  eab_id 
)

Create a GL_VERTEX_ARRAY for a given mesh (V,F)

Parameters
[in]V#V by dim list of mesh vertex positions
[in]F#F by 3 list of mesh triangle indices into V
[out]va_idid of vertex array
[out]ab_idid of array buffer (vertex buffer object)
[out]eab_idid of element array buffer (element/face buffer object)
Note
Unlike most libigl functions, the input Eigen matrices must be Eigen::PlainObjectBase because we want to directly access it's underlying storage. It cannot be Eigen::MatrixBase (see http://stackoverflow.com/questions/25094948/)