- Timestamp:
- Mar 31, 2005, 3:16:40 AM (20 years ago)
- Location:
- orxonox/branches/textEngine/src
- Files:
-
- 5 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); -
orxonox/branches/textEngine/src/orxonox.cc
r3681 r3693 33 33 #include "graphics_engine.h" 34 34 #include "resource_manager.h" 35 #include "glfont.h" 35 36 36 37 #include <string.h> … … 58 59 delete GraphicsEngine::getInstance(); // deleting the Graphics 59 60 delete ResourceManager::getInstance(); // deletes the Resource Manager 61 GLFont::disableFonts(); 60 62 } 61 63 … … 167 169 resourceManager->setDataDir("../data/"); 168 170 return 0; 171 PRINT(3)("initializing TextEngine\n"); 172 GLFont::enableFonts(); 169 173 } 170 174 -
orxonox/branches/textEngine/src/story_entities/world.cc
r3681 r3693 39 39 #include "glmenu_imagescreen.h" 40 40 #include "fontset.h" 41 #include "glfont.h" 41 42 #include "list.h" 42 43 … … 202 203 testFont = new FontSet(); 203 204 testFont->buildFont("../data/pictures/font.tga"); 205 tmpFont = new GLFont("Alpha Sentry.ttf", 20); 204 206 this->glmis->step(); 205 207 … … 594 596 595 597 testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION); 598 tmpFont->draw(); 596 599 597 600 lightMan->draw(); // must be at the end of the drawing procedure, otherwise Light cannot be handled as PNodes // -
orxonox/branches/textEngine/src/story_entities/world.h
r3681 r3693 22 22 class LightManager; 23 23 class FontSet; 24 class GLFont; 24 25 class Terrain; 25 26 class GarbageCollector; … … 96 97 97 98 FontSet* testFont; //!< A test Font. \todo fix this, so it is for real. 99 GLFont* tmpFont; //!< tmpFont \todo fix 98 100 GLMenuImageScreen* glmis; //!< The Level-Loader Display 99 101
Note: See TracChangeset
for help on using the changeset viewer.