load_shader.h 1006 B

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