create_shader_program.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #ifndef IGL_CREATE_SHADER_PROGRAM_H
  2. #define IGL_CREATE_SHADER_PROGRAM_H
  3. #include "igl_inline.h"
  4. #include <string>
  5. #include <map>
  6. #ifdef __APPLE__
  7. # include <OpenGL/gl.h>
  8. #elif defined(_WIN32)
  9. # define NOMINMAX
  10. # include <Windows.h>
  11. # undef NOMINMAX
  12. #else
  13. #define GL_GLEXT_PROTOTYPES
  14. # include <GL/gl.h>
  15. # include <GL/glext.h>
  16. #endif
  17. namespace igl
  18. {
  19. // Create a shader program with a vertex and fragments shader loading from
  20. // source strings and vertex attributes assigned from a map before linking the
  21. // shaders to the program, making it ready to use with glUseProgram(id)
  22. // Inputs:
  23. // vert_source string containing source code of vertex shader
  24. // frag_source string containing source code of fragment shader
  25. // attrib map containing table of vertex attribute strings add their
  26. // correspondingly ids (generated previously using glBindAttribLocation)
  27. // Outputs:
  28. // id index id of created shader, set to 0 on error
  29. // Returns true on success, false on error
  30. //
  31. // Note: Caller is responsible for making sure that current value of id is not
  32. // leaking a shader (since it will be overwritten)
  33. //
  34. // See also: destroy_shader_program
  35. IGL_INLINE bool create_shader_program(
  36. const std::string vert_source,
  37. const std::string frag_source,
  38. const std::map<std::string,GLuint> attrib,
  39. GLuint & id);
  40. }
  41. #ifdef IGL_HEADER_ONLY
  42. # include "create_shader_program.cpp"
  43. #endif
  44. #endif