Utils.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <GL/glew.h>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include "client/Utils.h"
  5. bool checkAndPrintError(const char* message)
  6. {
  7. GLenum error = glGetError();
  8. switch(error)
  9. {
  10. case GL_NO_ERROR:
  11. return false;
  12. case GL_INVALID_ENUM:
  13. std::cout << message << ": an unacceptable value is specified for an enumerated argument.\n";
  14. break;
  15. case GL_INVALID_VALUE:
  16. std::cout << message << ": a numeric argument is out of range.\n";
  17. break;
  18. case GL_INVALID_OPERATION:
  19. std::cout << message << ": the specified operation is not allowed in the current state.\n";
  20. break;
  21. case GL_INVALID_FRAMEBUFFER_OPERATION:
  22. std::cout << message << ": the framebuffer object is not complete.\n";
  23. break;
  24. case GL_OUT_OF_MEMORY:
  25. std::cout << message << ": there is not enough memory left to execute the command.\n";
  26. break;
  27. case GL_STACK_UNDERFLOW:
  28. std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow.\n";
  29. break;
  30. case GL_STACK_OVERFLOW:
  31. std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow.\n";
  32. break;
  33. default:
  34. std::cout << message << ": unknown OpenGL error: " << error << "\n";
  35. }
  36. return true;
  37. }
  38. float interpolate(float lag, float from, float to)
  39. {
  40. return from + lag * (to - from);
  41. }
  42. void printMatrix(const float* data)
  43. {
  44. std::cout << "MatrixData\n(\n";
  45. std::cout << std::fixed << std::setprecision(5);
  46. for(int i = 0; i < 4; i++)
  47. {
  48. std::cout << std::setw(15);
  49. std::cout << data[i] << ", ";
  50. std::cout << std::setw(15);
  51. std::cout << data[i + 4] << ", ";
  52. std::cout << std::setw(15);
  53. std::cout << data[i + 8] << ", ";
  54. std::cout << std::setw(15);
  55. std::cout << data[i + 12] << "\n";
  56. }
  57. std::cout << std::defaultfloat;
  58. std::cout << ")\n";
  59. }