glut_2d.cpp

Go to the documentation of this file.
00001 /*
00002  * glut_2d.cpp
00003  *
00004  * Copyright (C) 2008,2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Implementation of various 2D glut helper methods.
00032  * See glut_2d.h
00033  */
00034 
00035 // includes --------------------------------------------------------------------
00036 #include "glut_2d.h"                    // always include our own header first!
00037 
00038 
00039 namespace glut {
00040 
00041 ////////////////////////////////////////////////////////////////////////////////
00042 //
00043 //      static helper methods
00044 //
00045 ////////////////////////////////////////////////////////////////////////////////
00046 
00047 
00048 
00049 ////////////////////////////////////////////////////////////////////////////////
00050 //
00051 //      public API
00052 //
00053 ////////////////////////////////////////////////////////////////////////////////
00054 
00055 void
00056 push2D
00057 (
00058 IN int screenWidth,
00059 IN int screenHeight
00060 )
00061 {
00062         ASSERT(screenWidth > 0, "Bad width: %d", screenWidth);
00063         ASSERT(screenHeight > 0, "Bad height: %d", screenHeight);
00064 
00065         // turn off expensive 3D operations
00066 //      glDisable(GL_LIGHTING);
00067 //      glDisable(GL_DEPTH_TEST);
00068 //      glDisable(GL_TEXTURE_2D);
00069 
00070         glMatrixMode(GL_PROJECTION);
00071         glPushMatrix();
00072         glLoadIdentity();
00073         glOrtho(0, screenWidth, 0, screenHeight, -1, 1);
00074 
00075         glMatrixMode(GL_MODELVIEW);
00076         glPushMatrix();
00077         glLoadIdentity();
00078 
00079         // swap y-coordinate (opposite of OpenGL convention)
00080         glScalef(1, -1 ,1);     // positive Y is down
00081         glTranslatef(0, -screenHeight, 0); // y=0 is top of screen
00082 }
00083 
00084 
00085 
00086 void
00087 pop2D
00088 (
00089 void
00090 )
00091 {
00092         glScalef(1, 1, 1);
00093 
00094         glMatrixMode(GL_MODELVIEW);
00095         glPopMatrix();
00096 
00097         glMatrixMode(GL_PROJECTION);
00098         glPopMatrix();
00099 }
00100 
00101 
00102 
00103 void
00104 drawCursor
00105 (
00106 IN int x,
00107 IN int y
00108 )
00109 {
00110         glColor3f(1.0, 1.0, 1.0);
00111         glRecti(x - 2, y - 2, x + 2, y + 2);
00112 }
00113 
00114 
00115 
00116 };      // glut namespace
00117