|
- /*
- ==============================================================================
-
- 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::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
- }
-
- void OpenGLHelpers::setPerspective (double fovy, double aspect, double zNear, double zFar)
- {
- const double ymax = zNear * tan (fovy * double_Pi / 360.0);
- const double ymin = -ymax;
-
- #if JUCE_OPENGL_ES
- glFrustumf (ymin * aspect, ymax * aspect, ymin, ymax, zNear, zFar);
- #else
- 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)
- {
- glColor4f (colour.getFloatRed(), colour.getFloatGreen(),
- colour.getFloatBlue(), colour.getFloatAlpha());
-
- #if JUCE_OPENGL_ES
- 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 };
-
- 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);
-
- #else
- glBegin (GL_QUADS);
- glTexCoord2i (0, 0); glVertex2f (x1, y1);
- glTexCoord2i (1, 0); glVertex2f (x2, y2);
- glTexCoord2i (1, 1); glVertex2f (x3, y3);
- glTexCoord2i (0, 1); glVertex2f (x4, y4);
- glEnd();
- #endif
- }
-
- 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)
- {
- glColor4f (colour.getFloatRed(), colour.getFloatGreen(),
- colour.getFloatBlue(), colour.getFloatAlpha());
-
- #if JUCE_OPENGL_ES
- 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 };
-
- 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);
-
- #else
- glBegin (GL_QUADS);
- glTexCoord2i (0, 0); glVertex3f (x1, y1, z1);
- glTexCoord2i (1, 0); glVertex3f (x2, y2, z2);
- glTexCoord2i (1, 1); glVertex3f (x3, y3, z3);
- glTexCoord2i (0, 1); glVertex3f (x4, y4, z4);
- glEnd();
- #endif
- }
-
- END_JUCE_NAMESPACE
|