create_shader_program.h 1.5 KB

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