Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3693 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
Mar 31, 2005, 3:16:40 AM (20 years ago)
Author:
bensch
Message:

orxonox/brnaches/textEngine: working with some default text, but far from finished

Location:
orxonox/branches/textEngine/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc

    r3692 r3693  
    5353#include "debug.h"
    5454
    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()
     55GLFont::GLFont(const char* fontFile, unsigned int fontSize)
     56{
     57  this->init(fontFile, fontSize);
     58}
     59
     60GLFont::~GLFont(void)
    7861{
    7962  if (this->font)
     
    117100
    118101
    119 bool GLFont::init(const char* fontFile)
    120 {
     102bool GLFont::init(const char* fontFile, unsigned int fontSize)
     103{
     104  if (!GLFont::ttfInitialized)
     105    GLFont::enableFonts();
     106
    121107  // setting default values.
    122108  this->font = NULL;
    123109  this->fontFile = NULL;
    124   this->fontSize = 16;
     110
     111 
     112  this->setSize(fontSize);
    125113 
    126114  this->renderStyle = TTF_STYLE_NORMAL;
    127115
    128 
    129   if (!GLFont::ttfInitialized)
    130     GLFont::enableFonts();
     116  this->setFont(fontFile);
     117
     118  this->setText( FONT_DEFAULT_TEXT);
     119
    131120}
    132121
     
    155144  this->text = new char[strlen(text)+1];
    156145  strcpy(this->text, text);
     146
     147  this->createTexture();
    157148}
    158149
     
    193184
    194185
     186void GLFont::setPosition(int x, int y)
     187{
     188  this->positionX = x;
     189  this->positionY = y;
     190}
     191
     192void 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
    195208
    196209void GLFont::createTexture(void)
     
    198211  GLfloat texcoord[4];
    199212  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);
    202215}
    203216
     
    263276}
    264277
    265 void GLFont::setPosition(int x, int y)
    266 {
    267 
    268 }
    269 
    270278void GLFont::renderText(void)
    271279{
     
    274282
    275283
    276 void GLFont::renderText(const char* text, int x, int y)
    277 {
    278   // enter the 2D-Mode
    279 
    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-Mode
    313   glMatrixMode(GL_MODELVIEW);
    314   glPopMatrix();
    315  
    316   glMatrixMode(GL_PROJECTION);
    317   glPopMatrix();
    318  
    319   glPopAttrib();
    320 }
    321284
    322285void GLFont::enter2DMode()
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.h

    r3692 r3693  
    99#include "glincl.h"
    1010#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
    1121
    1222
     
    2939class GLFont
    3040{
    31  
    32  private:
    33 
    34    
    35 
    3641 public:
    37   GLFont();
    38   GLFont(const char* fontFile);
     42  GLFont(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
    3943  virtual ~GLFont();
    4044
    4145  static void enableFonts(void);
    4246  static void disableFonts(void);
    43 
    4447
    4548  bool setFont(const char* fontFile);
     
    5558  void renderText(void);
    5659  void renderText(const char* text, int x, int y);
     60
     61  virtual void draw(void);
    5762
    5863 private:
     
    7277  GLfloat* texcoord;
    7378
    74   bool init(const char* fontFile);
     79  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
    7580  int getMaxHeight(void);
    7681  int getMaxAscent(void);
  • orxonox/branches/textEngine/src/orxonox.cc

    r3681 r3693  
    3333#include "graphics_engine.h"
    3434#include "resource_manager.h"
     35#include "glfont.h"
    3536
    3637#include <string.h>
     
    5859  delete GraphicsEngine::getInstance(); // deleting the Graphics
    5960  delete ResourceManager::getInstance(); // deletes the Resource Manager
     61  GLFont::disableFonts();
    6062}
    6163
     
    167169  resourceManager->setDataDir("../data/");
    168170  return 0;
     171  PRINT(3)("initializing TextEngine\n");
     172  GLFont::enableFonts();
    169173}
    170174
  • orxonox/branches/textEngine/src/story_entities/world.cc

    r3681 r3693  
    3939#include "glmenu_imagescreen.h"
    4040#include "fontset.h"
     41#include "glfont.h"
    4142#include "list.h"
    4243
     
    202203      testFont = new FontSet();
    203204      testFont->buildFont("../data/pictures/font.tga");
     205      tmpFont = new GLFont("Alpha Sentry.ttf", 20);
    204206      this->glmis->step();
    205207
     
    594596
    595597  testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION);
     598  tmpFont->draw();
    596599
    597600  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  
    2222class LightManager;
    2323class FontSet;
     24class GLFont;
    2425class Terrain;
    2526class GarbageCollector;
     
    9697
    9798  FontSet* testFont;            //!< A test Font. \todo fix this, so it is for real.
     99  GLFont* tmpFont;              //!< tmpFont \todo fix
    98100  GLMenuImageScreen* glmis;     //!< The Level-Loader Display
    99101
Note: See TracChangeset for help on using the changeset viewer.