The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

134 lines
4.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. BEGIN_JUCE_NAMESPACE
  19. void OpenGLHelpers::resetErrorState()
  20. {
  21. while (glGetError() != GL_NO_ERROR) {}
  22. }
  23. void OpenGLHelpers::clear (const Colour& colour)
  24. {
  25. glClearColor (colour.getFloatRed(), colour.getFloatGreen(),
  26. colour.getFloatBlue(), colour.getFloatAlpha());
  27. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  28. }
  29. void OpenGLHelpers::prepareFor2D (int width, int height)
  30. {
  31. glMatrixMode (GL_PROJECTION);
  32. glLoadIdentity();
  33. #if JUCE_OPENGL_ES
  34. glOrthof (0.0f, (float) width, 0.0f, (float) height, 0.0f, 1.0f);
  35. #else
  36. glOrtho (0.0, width, 0.0, height, 0, 1);
  37. #endif
  38. }
  39. void OpenGLHelpers::setPerspective (double fovy, double aspect, double zNear, double zFar)
  40. {
  41. const double ymax = zNear * tan (fovy * double_Pi / 360.0);
  42. const double ymin = -ymax;
  43. #if JUCE_OPENGL_ES
  44. glFrustumf (ymin * aspect, ymax * aspect, ymin, ymax, zNear, zFar);
  45. #else
  46. glFrustum (ymin * aspect, ymax * aspect, ymin, ymax, zNear, zFar);
  47. #endif
  48. }
  49. void OpenGLHelpers::drawQuad2D (float x1, float y1,
  50. float x2, float y2,
  51. float x3, float y3,
  52. float x4, float y4,
  53. const Colour& colour)
  54. {
  55. glColor4f (colour.getFloatRed(), colour.getFloatGreen(),
  56. colour.getFloatBlue(), colour.getFloatAlpha());
  57. #if JUCE_OPENGL_ES
  58. const GLfloat vertices[] = { x1, y1, x2, y2, x4, y4, x3, y3 };
  59. const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f };
  60. glEnableClientState (GL_VERTEX_ARRAY);
  61. glVertexPointer (2, GL_FLOAT, 0, vertices);
  62. glEnableClientState (GL_TEXTURE_COORD_ARRAY);
  63. glTexCoordPointer (2, GL_FLOAT, 0, textureCoords);
  64. glDisableClientState (GL_COLOR_ARRAY);
  65. glDisableClientState (GL_NORMAL_ARRAY);
  66. glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
  67. #else
  68. glBegin (GL_QUADS);
  69. glTexCoord2i (0, 0); glVertex2f (x1, y1);
  70. glTexCoord2i (1, 0); glVertex2f (x2, y2);
  71. glTexCoord2i (1, 1); glVertex2f (x3, y3);
  72. glTexCoord2i (0, 1); glVertex2f (x4, y4);
  73. glEnd();
  74. #endif
  75. }
  76. void OpenGLHelpers::drawQuad3D (float x1, float y1, float z1,
  77. float x2, float y2, float z2,
  78. float x3, float y3, float z3,
  79. float x4, float y4, float z4,
  80. const Colour& colour)
  81. {
  82. glColor4f (colour.getFloatRed(), colour.getFloatGreen(),
  83. colour.getFloatBlue(), colour.getFloatAlpha());
  84. #if JUCE_OPENGL_ES
  85. const GLfloat vertices[] = { x1, y1, z1, x2, y2, z2, x4, y4, z4, x3, y3, z3 };
  86. const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f };
  87. glEnableClientState (GL_VERTEX_ARRAY);
  88. glVertexPointer (3, GL_FLOAT, 0, vertices);
  89. glEnableClientState (GL_TEXTURE_COORD_ARRAY);
  90. glTexCoordPointer (2, GL_FLOAT, 0, textureCoords);
  91. glDisableClientState (GL_COLOR_ARRAY);
  92. glDisableClientState (GL_NORMAL_ARRAY);
  93. glDrawArrays (GL_TRIANGLE_STRIP, 0, 4);
  94. #else
  95. glBegin (GL_QUADS);
  96. glTexCoord2i (0, 0); glVertex3f (x1, y1, z1);
  97. glTexCoord2i (1, 0); glVertex3f (x2, y2, z2);
  98. glTexCoord2i (1, 1); glVertex3f (x3, y3, z3);
  99. glTexCoord2i (0, 1); glVertex3f (x4, y4, z4);
  100. glEnd();
  101. #endif
  102. }
  103. END_JUCE_NAMESPACE