Changeset 3693 in orxonox.OLD for orxonox/branches/textEngine/src/lib/graphics/font
- Timestamp:
- Mar 31, 2005, 3:16:40 AM (20 years ago)
- Location:
- orxonox/branches/textEngine/src/lib/graphics/font
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc
r3692 r3693 53 53 #include "debug.h" 54 54 55 56 #define DEFAULT_SIZE 18 57 #define DEFAULT_TEXT "orxonox 1234567890" 58 #define DEFAULT_COLOR_R 256 59 #define DEFAULT_COLOR_G 256 60 #define DEFAULT_COLOR_B 256 61 #define NUM_COLORS 256 62 63 64 65 GLFont::GLFont() 66 { 67 this->init(""); 68 69 } 70 71 72 GLFont::GLFont(const char* fontFile) 73 { 74 this->init(fontFile); 75 } 76 77 GLFont::~GLFont() 55 GLFont::GLFont(const char* fontFile, unsigned int fontSize) 56 { 57 this->init(fontFile, fontSize); 58 } 59 60 GLFont::~GLFont(void) 78 61 { 79 62 if (this->font) … … 117 100 118 101 119 bool GLFont::init(const char* fontFile) 120 { 102 bool GLFont::init(const char* fontFile, unsigned int fontSize) 103 { 104 if (!GLFont::ttfInitialized) 105 GLFont::enableFonts(); 106 121 107 // setting default values. 122 108 this->font = NULL; 123 109 this->fontFile = NULL; 124 this->fontSize = 16; 110 111 112 this->setSize(fontSize); 125 113 126 114 this->renderStyle = TTF_STYLE_NORMAL; 127 115 128 129 if (!GLFont::ttfInitialized) 130 GLFont::enableFonts(); 116 this->setFont(fontFile); 117 118 this->setText( FONT_DEFAULT_TEXT); 119 131 120 } 132 121 … … 155 144 this->text = new char[strlen(text)+1]; 156 145 strcpy(this->text, text); 146 147 this->createTexture(); 157 148 } 158 149 … … 193 184 194 185 186 void GLFont::setPosition(int x, int y) 187 { 188 this->positionX = x; 189 this->positionY = y; 190 } 191 192 void GLFont::draw(void) 193 { 194 this->enter2DMode(); 195 glBindTexture(GL_TEXTURE_2D, texture); 196 glEnable(GL_TEXTURE_2D); 197 glBegin(GL_QUADS); 198 glTexCoord2f(0, 0); glVertex2i(20, 20 ); 199 glTexCoord2f(1, 0); glVertex2i(200, 20 ); 200 glTexCoord2f(1, 1); glVertex2i(200, 80); 201 glTexCoord2f(0, 1); glVertex2i(20, 80); 202 glEnd(); 203 this->leave2DMode(); 204 205 } 206 207 195 208 196 209 void GLFont::createTexture(void) … … 198 211 GLfloat texcoord[4]; 199 212 SDL_Surface* tmpSurf = TTF_RenderText_Blended(this->font, this->text, this->color); 200 texture = loadTexture(tmpSurf, texcoord);201 213 if (tmpSurf) 214 this->texture = loadTexture(tmpSurf, texcoord); 202 215 } 203 216 … … 263 276 } 264 277 265 void GLFont::setPosition(int x, int y)266 {267 268 }269 270 278 void GLFont::renderText(void) 271 279 { … … 274 282 275 283 276 void GLFont::renderText(const char* text, int x, int y)277 {278 // enter the 2D-Mode279 280 SDL_Surface *screen = SDL_GetVideoSurface();281 282 /* Note, there may be other things you need to change,283 depending on how you have your OpenGL state set up.284 */285 glPushAttrib(GL_ENABLE_BIT);286 glDisable(GL_DEPTH_TEST);287 glDisable(GL_CULL_FACE);288 glEnable(GL_TEXTURE_2D);289 290 /* This allows alpha blending of 2D textures with the scene */291 glEnable(GL_BLEND);292 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);293 294 glViewport(0, 0, screen->w, screen->h);295 296 glMatrixMode(GL_PROJECTION);297 glPushMatrix();298 glLoadIdentity();299 300 glOrtho(0.0, (GLdouble)screen->w, (GLdouble)screen->h, 0.0, 0.0, 1.0);301 302 glMatrixMode(GL_MODELVIEW);303 glPushMatrix();304 glLoadIdentity();305 306 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);307 308 309 310 311 312 // Leave the 2D-Mode313 glMatrixMode(GL_MODELVIEW);314 glPopMatrix();315 316 glMatrixMode(GL_PROJECTION);317 glPopMatrix();318 319 glPopAttrib();320 }321 284 322 285 void GLFont::enter2DMode() -
orxonox/branches/textEngine/src/lib/graphics/font/glfont.h
r3692 r3693 9 9 #include "glincl.h" 10 10 #include "SDL_ttf.h" 11 12 13 /* some default values */ 14 #define FONT_DEFAULT_SIZE 18 15 #define FONT_DEFAULT_TEXT "orxonox 1234567890" 16 #define FONT_DEFAULT_COLOR_R 256 17 #define FONT_DEFAULT_COLOR_G 256 18 #define FONT_DEFAULT_COLOR_B 256 19 #define FONT_NUM_COLORS 256 20 11 21 12 22 … … 29 39 class GLFont 30 40 { 31 32 private:33 34 35 36 41 public: 37 GLFont(); 38 GLFont(const char* fontFile); 42 GLFont(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE); 39 43 virtual ~GLFont(); 40 44 41 45 static void enableFonts(void); 42 46 static void disableFonts(void); 43 44 47 45 48 bool setFont(const char* fontFile); … … 55 58 void renderText(void); 56 59 void renderText(const char* text, int x, int y); 60 61 virtual void draw(void); 57 62 58 63 private: … … 72 77 GLfloat* texcoord; 73 78 74 bool init(const char* fontFile );79 bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE); 75 80 int getMaxHeight(void); 76 81 int getMaxAscent(void);
Note: See TracChangeset
for help on using the changeset viewer.