Open Source Tomb Raider Engine
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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*!
  2. * \file src/Window.cpp
  3. * \brief windowing implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include <assert.h>
  8. #ifdef __APPLE__
  9. #include <OpenGL/gl.h>
  10. #include <OpenGL/glu.h>
  11. #else
  12. #include <GL/gl.h>
  13. #include <GL/glu.h>
  14. #endif
  15. #include "math/math.h"
  16. #include "Window.h"
  17. Window::~Window() {
  18. }
  19. void Window::resizeGL(unsigned int w, unsigned int h) {
  20. float fovY = 45.0f;
  21. float clipNear = 4.0f;
  22. float clipFar = 4000.0f;
  23. assert(w > 0);
  24. assert(h > 0);
  25. glViewport(0, 0, w, h);
  26. glMatrixMode(GL_PROJECTION);
  27. glLoadIdentity();
  28. // Adjust clipping
  29. GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
  30. GLfloat fW = fH * ((GLfloat)w) / ((GLfloat)h);
  31. glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
  32. glMatrixMode(GL_MODELVIEW);
  33. glLoadIdentity();
  34. }
  35. void Window::glEnter2D(unsigned int width, unsigned int height) {
  36. glPushAttrib(GL_ENABLE_BIT);
  37. glDisable(GL_DEPTH_TEST);
  38. glDisable(GL_CULL_FACE);
  39. glEnable(GL_TEXTURE_2D);
  40. /* This allows alpha blending of 2D textures with the scene */
  41. glEnable(GL_BLEND);
  42. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  43. glViewport(0, 0, width, height);
  44. glMatrixMode(GL_PROJECTION);
  45. glPushMatrix();
  46. glLoadIdentity();
  47. glOrtho(0.0, (GLdouble)width, (GLdouble)height, 0.0, 0.0, 1.0);
  48. glMatrixMode(GL_MODELVIEW);
  49. glPushMatrix();
  50. glLoadIdentity();
  51. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  52. }
  53. void Window::glExit2D() {
  54. glMatrixMode(GL_MODELVIEW);
  55. glPopMatrix();
  56. glMatrixMode(GL_PROJECTION);
  57. glPopMatrix();
  58. glPopAttrib();
  59. glMatrixMode(GL_MODELVIEW);
  60. }