gl_window.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2023 RealSense, Inc. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <librealsense2/rs.hpp> // Include RealSense Cross Platform API
  16. #if defined (ACCELERATE_GPU_WITH_GLSL)
  17. #define GL_SILENCE_DEPRECATION
  18. #define GLFW_INCLUDE_GLU
  19. #include <GLFW/glfw3.h>
  20. #include <GL/gl.h>
  21. #include <iostream>
  22. #include <librealsense2-gl/rs_processing_gl.hpp> // Include GPU-Processing API
  23. #ifndef PI
  24. #define PI 3.14159265358979323846
  25. #define PI_FL 3.141592f
  26. #endif
  27. class GLwindow
  28. {
  29. public:
  30. GLwindow(int width, int height, const char* title)
  31. : _width(width), _height(height)
  32. {
  33. glfwInit();
  34. glfwWindowHint(GLFW_VISIBLE, 0);
  35. win = glfwCreateWindow(width, height, title, nullptr, nullptr);
  36. if (!win)
  37. throw std::runtime_error("Could not open OpenGL window, please check your graphic drivers or use the textual SDK tools");
  38. glfwMakeContextCurrent(win);
  39. glfwSetWindowUserPointer(win, this);
  40. }
  41. ~GLwindow()
  42. {
  43. glfwDestroyWindow(win);
  44. glfwTerminate();
  45. }
  46. void close()
  47. {
  48. glfwSetWindowShouldClose(win, 1);
  49. }
  50. float width() const { return float(_width); }
  51. float height() const { return float(_height); }
  52. operator bool()
  53. {
  54. auto res = !glfwWindowShouldClose(win);
  55. glfwPollEvents();
  56. return res;
  57. }
  58. operator GLFWwindow* () { return win; }
  59. private:
  60. GLFWwindow* win;
  61. int _width, _height;
  62. };
  63. #endif