GL.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <GL/glew.h>
  2. #include <iostream>
  3. #include "wrapper/GL.h"
  4. bool GL::checkAndPrintError(const char* message) {
  5. GLenum error = glGetError();
  6. switch(error) {
  7. case GL_NO_ERROR: return false;
  8. case GL_INVALID_ENUM:
  9. std::cout << message << ": an unacceptable value is specified for an enumerated argument\n";
  10. break;
  11. case GL_INVALID_VALUE: std::cout << message << ": a numeric argument is out of range\n"; break;
  12. case GL_INVALID_OPERATION:
  13. std::cout << message << ": the specified operation is not allowed in the current state\n";
  14. break;
  15. case GL_INVALID_FRAMEBUFFER_OPERATION:
  16. std::cout << message << ": the framebuffer object is not complete\n";
  17. break;
  18. case GL_OUT_OF_MEMORY:
  19. std::cout << message << ": there is not enough memory left to execute the command\n";
  20. break;
  21. case GL_STACK_UNDERFLOW:
  22. std::cout << message
  23. << ": an attempt has been made to perform an operation that would cause an internal stack to "
  24. "underflow\n";
  25. break;
  26. case GL_STACK_OVERFLOW:
  27. std::cout << message
  28. << ": an attempt has been made to perform an operation that would cause an internal stack to "
  29. "overflow\n";
  30. break;
  31. default: std::cout << message << ": unknown OpenGL error '" << error << "'\n";
  32. }
  33. return true;
  34. }
  35. void GL::enableDepthTesting() {
  36. glEnable(GL_DEPTH_TEST);
  37. }
  38. void GL::disableDepthTesting() {
  39. glDisable(GL_DEPTH_TEST);
  40. }
  41. void GL::bindMainFramebuffer() {
  42. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  43. }
  44. void GL::clearFramebuffer() {
  45. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  46. }
  47. void GL::enableBlending() {
  48. glEnable(GL_BLEND);
  49. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  50. glBlendEquation(GL_FUNC_ADD);
  51. }
  52. void GL::disableBlending() {
  53. glDisable(GL_BLEND);
  54. }
  55. void GL::setViewport(int width, int height) {
  56. glViewport(0, 0, width, height);
  57. }