source: GTP/branches/IllumWPdeliver2008dec/IlluminationWP/demos/Standalone/Hierarchical Systems Demo [OpenGL]/RESOURCES/include/glh/glh_glut_text.h @ 3255

Revision 3255, 4.3 KB checked in by szirmay, 15 years ago (diff)
Line 
1/*
2glh - is a platform-indepenedent C++ OpenGL helper library
3
4 
5    Copyright (c) 2000 Cass Everitt
6        Copyright (c) 2000 NVIDIA Corporation
7    All rights reserved.
8       
9    Redistribution and use in source and binary forms, with or
10    without modification, are permitted provided that the following
11    conditions are met:
12         
13        * Redistributions of source code must retain the above
14          copyright notice, this list of conditions and the following
15          disclaimer.
16               
17    * Redistributions in binary form must reproduce the above
18          copyright notice, this list of conditions and the following
19          disclaimer in the documentation and/or other materials
20          provided with the distribution.
21                 
22        * The names of contributors to this software may not be used
23          to endorse or promote products derived from this software
24          without specific prior written permission.
25                       
26        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27        ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29        FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
30        REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31        INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32        BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33        LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35        LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
36        ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37        POSSIBILITY OF SUCH DAMAGE.
38                         
39                               
40        Cass Everitt - cass@r3.nu
41*/
42
43#ifndef GLH_GLUT_TEXT_H
44#define GLH_GLUT_TEXT_H
45
46#include <glh/glh_obs.h>
47#include <glh/glh_text.h>
48
49#ifdef MACOS
50#include <GLUT/glut.h>
51#else
52#include <GL/glut.h>
53#endif
54
55namespace glh
56{
57       
58        struct glut_stroke_roman : font
59        {
60                glut_stroke_roman() : initialized(false) {}
61
62        virtual ~glut_stroke_roman() { }
63       
64        struct glyph
65                {
66                        float width;
67                        display_list dl;
68                };
69               
70               
71                // get font metrics
72                virtual float get_ascent()
73                {  return 119.05f; }
74                virtual float get_descent()
75                {  return  33.33f; }
76                virtual float get_width(int i)
77                {
78                        if(32 <= i && i <= 127)
79                        {
80                                if(! initialized) init();
81                                return glyphs[i].width;
82                        }
83                        return 0;
84                }
85               
86                // draw
87                virtual void  render(int i)
88                {
89                        if(32 <= i && i <= 127)
90                        {
91                                if(! initialized) init();
92                                glyphs[i].dl.call_list();
93                        }                       
94                }
95
96                virtual void initialize() { if(! initialized) init(); }
97               
98                bool initialized;
99                glyph glyphs[128];
100               
101        private:
102                       
103                void init()
104                {
105                        initialized = true;
106                        GLfloat m[16];
107                        glColorMask(0,0,0,0);
108                        glDepthMask(0);
109                        glStencilMask(0);
110                        for(int i=32; i < 128; i++)
111                        {
112                                glPushMatrix();
113                                glLoadIdentity();
114
115                                // build display list
116                                glyphs[i].dl.new_list(GL_COMPILE_AND_EXECUTE);
117                                glutStrokeCharacter(GLUT_STROKE_ROMAN, i);
118                                glyphs[i].dl.end_list();
119                                // get *float* character width (glut only returns integer width)
120                                glGetFloatv(GL_MODELVIEW_MATRIX, m);
121                                glyphs[i].width = m[12];
122
123                                glPopMatrix();
124                        }
125                        glColorMask(1,1,1,1);
126                        glDepthMask(1);
127                        glStencilMask(1);
128                }
129
130        };
131       
132       
133        struct glut_stroke_mono_roman : font
134        {
135                glut_stroke_mono_roman() : initialized(false) {}
136               
137        virtual ~glut_stroke_mono_roman() { }
138       
139                struct glyph
140                {
141                        display_list dl;
142                };
143               
144               
145                // get font metrics
146                virtual float get_ascent()
147                {  return 119.05f; }
148                virtual float get_descent()
149                {  return  33.33f; }
150                virtual float get_width(int i)
151                {
152                        if(32 <= i && i <= 127)
153                        {
154                                if(! initialized) init();
155                                return 104.76;
156                        }
157                        return 0;
158                }
159               
160                // draw
161                virtual void  render(int i)
162                {
163                        if(32 <= i && i <= 127)
164                        {
165                                if(! initialized) init();
166                                glyphs[i].dl.call_list();
167                        }                       
168                }
169
170                virtual void initialize() { if(! initialized) init(); }
171               
172                bool initialized;
173                glyph glyphs[128];
174               
175        private:
176                       
177                void init()
178                {
179                        initialized = true;
180                        for(int i=32; i < 128; i++)
181                        {
182                                // build display list
183                                glyphs[i].dl.new_list(GL_COMPILE);
184                                glutStrokeCharacter(GLUT_STROKE_MONO_ROMAN, i);
185                                glyphs[i].dl.end_list();
186                        }
187                }
188
189        };
190       
191       
192       
193}
194
195#endif
Note: See TracBrowser for help on using the repository browser.