glh_glut_text.h
Go to the documentation of this file.
00001 /*
00002 glh - is a platform-indepenedent C++ OpenGL helper library 
00003 
00004   
00005     Copyright (c) 2000 Cass Everitt
00006         Copyright (c) 2000 NVIDIA Corporation
00007     All rights reserved.
00008         
00009     Redistribution and use in source and binary forms, with or
00010     without modification, are permitted provided that the following
00011     conditions are met:
00012           
00013         * Redistributions of source code must retain the above
00014           copyright notice, this list of conditions and the following
00015           disclaimer.
00016                 
00017     * Redistributions in binary form must reproduce the above
00018           copyright notice, this list of conditions and the following
00019           disclaimer in the documentation and/or other materials
00020           provided with the distribution.
00021                   
00022         * The names of contributors to this software may not be used
00023           to endorse or promote products derived from this software
00024           without specific prior written permission. 
00025                         
00026         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00027         ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00028         LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00029         FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00030         REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00031         INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00032         BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00033         LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00034         CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00035         LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00036         ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00037         POSSIBILITY OF SUCH DAMAGE. 
00038                           
00039                                 
00040         Cass Everitt - cass@r3.nu
00041 */
00042 
00043 #ifndef GLH_GLUT_TEXT_H
00044 #define GLH_GLUT_TEXT_H
00045 
00046 #include <glh/glh_obs.h>
00047 #include <glh/glh_text.h>
00048 
00049 #ifdef MACOS
00050 #include <GLUT/glut.h>
00051 #else
00052 #include <GL/glut.h>
00053 #endif
00054 
00055 namespace glh
00056 {
00057         
00058         struct glut_stroke_roman : font
00059         {
00060                 glut_stroke_roman() : initialized(false) {}
00061 
00062         virtual ~glut_stroke_roman() { } 
00063         
00064         struct glyph
00065                 {
00066                         float width;
00067                         display_list dl;
00068                 };
00069                 
00070                 
00071                 // get font metrics
00072                 virtual float get_ascent()
00073                 {  return 119.05f; }
00074                 virtual float get_descent()
00075                 {  return  33.33f; }
00076                 virtual float get_width(int i)
00077                 {
00078                         if(32 <= i && i <= 127)
00079                         {
00080                                 if(! initialized) init();
00081                                 return glyphs[i].width;
00082                         }
00083                         return 0;
00084                 }
00085                 
00086                 // draw
00087                 virtual void  render(int i)
00088                 {
00089                         if(32 <= i && i <= 127)
00090                         {
00091                                 if(! initialized) init();
00092                                 glyphs[i].dl.call_list();
00093                         }                       
00094                 }
00095 
00096                 virtual void initialize() { if(! initialized) init(); }
00097                 
00098                 bool initialized;
00099                 glyph glyphs[128];
00100                 
00101         private:
00102                         
00103                 void init()
00104                 {
00105                         initialized = true;
00106                         GLfloat m[16];
00107                         glColorMask(0,0,0,0);
00108                         glDepthMask(0);
00109                         glStencilMask(0);
00110                         for(int i=32; i < 128; i++)
00111                         {
00112                                 glPushMatrix();
00113                                 glLoadIdentity();
00114 
00115                                 // build display list
00116                                 glyphs[i].dl.new_list(GL_COMPILE_AND_EXECUTE);
00117                                 glutStrokeCharacter(GLUT_STROKE_ROMAN, i);
00118                                 glyphs[i].dl.end_list();
00119                                 // get *float* character width (glut only returns integer width)
00120                                 glGetFloatv(GL_MODELVIEW_MATRIX, m);
00121                                 glyphs[i].width = m[12];
00122 
00123                                 glPopMatrix();
00124                         }
00125                         glColorMask(1,1,1,1);
00126                         glDepthMask(1);
00127                         glStencilMask(1);
00128                 }
00129 
00130         };
00131         
00132         
00133         struct glut_stroke_mono_roman : font
00134         {
00135                 glut_stroke_mono_roman() : initialized(false) {}
00136                 
00137         virtual ~glut_stroke_mono_roman() { }
00138         
00139                 struct glyph
00140                 {
00141                         display_list dl;
00142                 };
00143                 
00144                 
00145                 // get font metrics
00146                 virtual float get_ascent()
00147                 {  return 119.05f; }
00148                 virtual float get_descent()
00149                 {  return  33.33f; }
00150                 virtual float get_width(int i)
00151                 {
00152                         if(32 <= i && i <= 127)
00153                         {
00154                                 if(! initialized) init();
00155                                 return 104.76;
00156                         }
00157                         return 0;
00158                 }
00159                 
00160                 // draw
00161                 virtual void  render(int i)
00162                 {
00163                         if(32 <= i && i <= 127)
00164                         {
00165                                 if(! initialized) init();
00166                                 glyphs[i].dl.call_list();
00167                         }                       
00168                 }
00169 
00170                 virtual void initialize() { if(! initialized) init(); }
00171                 
00172                 bool initialized;
00173                 glyph glyphs[128];
00174                 
00175         private:
00176                         
00177                 void init()
00178                 {
00179                         initialized = true;
00180                         for(int i=32; i < 128; i++)
00181                         {
00182                                 // build display list
00183                                 glyphs[i].dl.new_list(GL_COMPILE);
00184                                 glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, i);
00185                                 glyphs[i].dl.end_list();
00186                         }
00187                 }
00188 
00189         };
00190         
00191         
00192         
00193 }
00194 
00195 #endif


nao_openni
Author(s): Bener SUAY
autogenerated on Mon Jan 6 2014 11:27:50