compile_shader.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "compile_shader.h"
  9. #include "report_gl_error.h"
  10. #include <iostream>
  11. IGL_INLINE GLuint igl::opengl::compile_shader(const GLint type, const char * str)
  12. {
  13. GLuint id = glCreateShader(type);
  14. report_gl_error("glCreateShader: ");
  15. glShaderSource(id,1,&str,NULL);
  16. report_gl_error("glShaderSource: ");
  17. glCompileShader(id);
  18. report_gl_error("glCompileShader: ");
  19. GLint status;
  20. glGetShaderiv(id, GL_COMPILE_STATUS, &status);
  21. if (status != GL_TRUE)
  22. {
  23. char buffer[512];
  24. if (type == GL_VERTEX_SHADER)
  25. std::cerr << "Vertex shader:" << std::endl;
  26. else if (type == GL_FRAGMENT_SHADER)
  27. std::cerr << "Fragment shader:" << std::endl;
  28. std::cerr << str << std::endl << std::endl;
  29. glGetShaderInfoLog(id, 512, NULL, buffer);
  30. std::cerr << "Error: " << std::endl << buffer << std::endl;
  31. }
  32. return id;
  33. }