load_shader.cpp 943 B

12345678910111213141516171819202122232425262728293031323334
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "load_shader.h"
  9. // Copyright Denis Kovacs 4/10/08
  10. #include "print_shader_info_log.h"
  11. #include <cstdio>
  12. IGL_INLINE GLuint igl::opengl::load_shader(
  13. const std::string & src,const GLenum type)
  14. {
  15. if(src.empty())
  16. {
  17. return (GLuint) 0;
  18. }
  19. GLuint s = glCreateShader(type);
  20. if(s == 0)
  21. {
  22. fprintf(stderr,"Error: load_shader() failed to create shader.\n");
  23. return 0;
  24. }
  25. // Pass shader source string
  26. const char *c = src.c_str();
  27. glShaderSource(s, 1, &c, NULL);
  28. glCompileShader(s);
  29. // Print info log (if any)
  30. igl::opengl::print_shader_info_log(s);
  31. return s;
  32. }