/* ============================================================================== This file is part of the JUCE library - "Jules' Utility Class Extensions" Copyright 2004-11 by Raw Material Software Ltd. ------------------------------------------------------------------------------ JUCE can be redistributed and/or modified under the terms of the GNU General Public License (Version 2), as published by the Free Software Foundation. A copy of the license is included in the JUCE distribution, or can be found online at www.gnu.org/licenses. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ------------------------------------------------------------------------------ To release a closed-source product which uses JUCE, commercial licenses are available: visit www.rawmaterialsoftware.com/juce for more information. ============================================================================== */ BEGIN_JUCE_NAMESPACE void OpenGLHelpers::resetErrorState() { while (glGetError() != GL_NO_ERROR) {} } void OpenGLHelpers::clear (const Colour& colour) { glClearColor (colour.getFloatRed(), colour.getFloatGreen(), colour.getFloatBlue(), colour.getFloatAlpha()); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } void OpenGLHelpers::setColour (const Colour& colour) { glColor4f (colour.getFloatRed(), colour.getFloatGreen(), colour.getFloatBlue(), colour.getFloatAlpha()); } void OpenGLHelpers::prepareFor2D (int width, int height) { glMatrixMode (GL_PROJECTION); glLoadIdentity(); #if JUCE_OPENGL_ES glOrthof (0.0f, (float) width, 0.0f, (float) height, 0.0f, 1.0f); #else glOrtho (0.0, width, 0.0, height, 0, 1); #endif glViewport (0, 0, width, height); } void OpenGLHelpers::setPerspective (double fovy, double aspect, double zNear, double zFar) { glLoadIdentity(); #if JUCE_OPENGL_ES const float ymax = (float) (zNear * tan (fovy * double_Pi / 360.0)); const float ymin = -ymax; glFrustumf (ymin * (float) aspect, ymax * (float) aspect, ymin, ymax, (float) zNear, (float) zFar); #else const double ymax = zNear * tan (fovy * double_Pi / 360.0); const double ymin = -ymax; glFrustum (ymin * aspect, ymax * aspect, ymin, ymax, zNear, zFar); #endif } void OpenGLHelpers::drawQuad2D (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, const Colour& colour) { const GLfloat vertices[] = { x1, y1, x2, y2, x4, y4, x3, y3 }; const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f }; setColour (colour); glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (2, GL_FLOAT, 0, vertices); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glTexCoordPointer (2, GL_FLOAT, 0, textureCoords); glDisableClientState (GL_COLOR_ARRAY); glDisableClientState (GL_NORMAL_ARRAY); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); } void OpenGLHelpers::drawQuad3D (float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4, const Colour& colour) { const GLfloat vertices[] = { x1, y1, z1, x2, y2, z2, x4, y4, z4, x3, y3, z3 }; const GLfloat textureCoords[] = { 0, 0, 1.0f, 0, 0, 1.0f, 1.0f, 1.0f }; setColour (colour); glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (3, GL_FLOAT, 0, vertices); glEnableClientState (GL_TEXTURE_COORD_ARRAY); glTexCoordPointer (2, GL_FLOAT, 0, textureCoords); glDisableClientState (GL_COLOR_ARRAY); glDisableClientState (GL_NORMAL_ARRAY); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4); } END_JUCE_NAMESPACE