You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

window.cpp 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * =====================================================================================
  3. *
  4. * Filename: window.cpp
  5. *
  6. * Description: SDL window wrapper
  7. *
  8. * Version: 1.0
  9. * Created: 03/24/2014 11:15:10 PM
  10. * Revision: none
  11. * Compiler: gcc
  12. *
  13. * Author: YOUR NAME (),
  14. * Organization:
  15. *
  16. * =====================================================================================
  17. */
  18. #include "window.h"
  19. #include <glm/gtc/matrix_transform.hpp>
  20. #include <GL/glew.h>
  21. #include <GL/gl.h>
  22. namespace vtk {
  23. void Window::activate() {
  24. glBindFramebuffer(GL_FRAMEBUFFER, 0);
  25. }
  26. bool Window::create() {
  27. window = SDL_CreateWindow(title.c_str(),
  28. SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
  29. mWidth, mHeight, SDL_WINDOW_OPENGL);
  30. context = SDL_GL_CreateContext(window);
  31. SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
  32. return true;
  33. }
  34. void Window::setTitle(const std::string& title) {
  35. this->title = title;
  36. }
  37. void Window::setResolution(const int& x, const int& y) {
  38. mWidth = x;
  39. mHeight = y;
  40. }
  41. std::pair<int, int> Window::getResolution() {
  42. std::pair<int, int> resolution;
  43. SDL_GetWindowSize(window, &resolution.first, &resolution.second);
  44. return resolution;
  45. }
  46. SDL_Window* Window::getWindow() {
  47. return window;
  48. }
  49. void Window::setFOV(const float& angle) {
  50. fov = angle;
  51. }
  52. glm::mat4 Window::getProjectionMatrix() {
  53. return glm::perspective(glm::radians(fov), (float)getAspect(), 0.1f, 500.0f);
  54. }
  55. }