Utils.cpp 2.1 KB

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