Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Window.cpp 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*!
  2. * \file src/Window.cpp
  3. * \brief windowing implementation
  4. *
  5. * \author xythobuz
  6. */
  7. #include <cstdio>
  8. #include <cstring>
  9. #include <assert.h>
  10. #ifdef __APPLE__
  11. #include <OpenGL/gl.h>
  12. #include <OpenGL/glu.h>
  13. #else
  14. #include <GL/gl.h>
  15. #include <GL/glu.h>
  16. #endif
  17. #include "math/math.h"
  18. #include "Window.h"
  19. Window::~Window() {
  20. }
  21. int Window::initializeGL() {
  22. // Print driver support information
  23. //printf("GL Vendor : %s\n", glGetString(GL_VENDOR));
  24. //printf("GL Renderer: %s\n", glGetString(GL_RENDERER));
  25. //printf("GL Version : %s\n", glGetString(GL_VERSION));
  26. // Testing for goodies
  27. const char *s = (const char *)glGetString(GL_EXTENSIONS);
  28. if ((s != NULL) && (s[0] != '\0')) {
  29. //! \todo MultiTexture flag
  30. //if (strstr(s, "GL_ARB_multitexture"))
  31. //mFlags |= Render::fMultiTexture;
  32. }
  33. // Set up Z buffer
  34. glEnable(GL_DEPTH_TEST);
  35. glDepthFunc(GL_LESS);
  36. // Set up culling
  37. glEnable(GL_CULL_FACE);
  38. glFrontFace(GL_CW);
  39. //glFrontFace(GL_CCW);
  40. //glCullFace(GL_FRONT);
  41. // Set background to black
  42. glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  43. // Disable lighting
  44. glDisable(GL_LIGHTING);
  45. // Set up alpha blending
  46. glEnable(GL_BLEND);
  47. glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
  48. //glEnable(GL_ALPHA_TEST); // Disable per pixel alpha blending
  49. glAlphaFunc(GL_GREATER, 0);
  50. glPointSize(5.0);
  51. // Setup shading
  52. glShadeModel(GL_SMOOTH);
  53. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  54. glHint(GL_FOG_HINT, GL_NICEST);
  55. glEnable(GL_COLOR_MATERIAL);
  56. glEnable(GL_DITHER);
  57. // AA polygon edges
  58. glEnable(GL_POLYGON_SMOOTH);
  59. glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
  60. glDisable(GL_LINE_SMOOTH);
  61. glDisable(GL_POINT_SMOOTH);
  62. glDisable(GL_AUTO_NORMAL);
  63. glDisable(GL_LOGIC_OP);
  64. glDisable(GL_TEXTURE_1D);
  65. glDisable(GL_STENCIL_TEST);
  66. glDisable(GL_FOG);
  67. glDisable(GL_NORMALIZE);
  68. glEnableClientState(GL_VERTEX_ARRAY);
  69. glDisableClientState(GL_EDGE_FLAG_ARRAY);
  70. glDisableClientState(GL_COLOR_ARRAY);
  71. glDisableClientState(GL_NORMAL_ARRAY);
  72. glPolygonMode(GL_FRONT, GL_FILL);
  73. glMatrixMode(GL_MODELVIEW);
  74. return 0;
  75. }
  76. void Window::resizeGL() {
  77. float fovY = 45.0f;
  78. float clipNear = 4.0f;
  79. float clipFar = 4000.0f;
  80. glViewport(0, 0, mWidth, mHeight);
  81. glMatrixMode(GL_PROJECTION);
  82. glLoadIdentity();
  83. // Adjust clipping
  84. GLfloat fH = tanf(fovY * OR_PI / 360.0f) * clipNear;
  85. GLfloat fW = fH * ((GLfloat)mWidth) / ((GLfloat)mHeight);
  86. glFrustum(-fW, fW, -fH, fH, clipNear, clipFar);
  87. glMatrixMode(GL_MODELVIEW);
  88. glLoadIdentity();
  89. }
  90. void Window::glEnter2D() {
  91. glPushAttrib(GL_ENABLE_BIT);
  92. glDisable(GL_DEPTH_TEST);
  93. glDisable(GL_CULL_FACE);
  94. glEnable(GL_TEXTURE_2D);
  95. /* This allows alpha blending of 2D textures with the scene */
  96. glEnable(GL_BLEND);
  97. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  98. glViewport(0, 0, mWidth, mHeight);
  99. glMatrixMode(GL_PROJECTION);
  100. glPushMatrix();
  101. glLoadIdentity();
  102. glOrtho(0.0, (GLdouble)mWidth, (GLdouble)mHeight, 0.0, 0.0, 1.0);
  103. glMatrixMode(GL_MODELVIEW);
  104. glPushMatrix();
  105. glLoadIdentity();
  106. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  107. }
  108. void Window::glExit2D() {
  109. glMatrixMode(GL_MODELVIEW);
  110. glPopMatrix();
  111. glMatrixMode(GL_PROJECTION);
  112. glPopMatrix();
  113. glPopAttrib();
  114. glMatrixMode(GL_MODELVIEW);
  115. }