Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Window.cpp 3.4KB

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