load_shader.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef IGL_LOAD_SHADER_H
  2. #define IGL_LOAD_SHADER_H
  3. #ifdef __APPLE__
  4. # include <OpenGL/gl.h>
  5. #else
  6. # ifdef _WIN32
  7. # define NOMINMAX
  8. # include <Windows.h>
  9. # undef NOMINMAX
  10. # endif
  11. # include <GL/gl.h>
  12. #endif
  13. namespace igl
  14. {
  15. // Creates and compiles a shader from a given string
  16. // Inputs:
  17. // src string containing GLSL shader code
  18. // type GLSL type of shader, one of:
  19. // GL_VERTEX_SHADER
  20. // GL_FRAGMENT_SHADER
  21. // GL_GEOMETRY_SHADER
  22. // Returns index id of the newly created shader, 0 on error
  23. inline GLuint load_shader(const char *src,const GLenum type);
  24. }
  25. // Implementation
  26. // Copyright Denis Kovacs 4/10/08
  27. #include "print_shader_info_log.h"
  28. #include <cstdio>
  29. inline GLuint igl::load_shader(const char *src,const GLenum type)
  30. {
  31. GLuint s = glCreateShader(type);
  32. if(s == 0)
  33. {
  34. fprintf(stderr,"Error: load_shader() failed to create shader.\n");
  35. return 0;
  36. }
  37. // Pass shader source string
  38. glShaderSource(s, 1, &src, NULL);
  39. glCompileShader(s);
  40. // Print info log (if any)
  41. igl::print_shader_info_log(s);
  42. return s;
  43. }
  44. #endif