VIZ++ Class: OpenGLStrokeFont

 VIZ++ Class Library  VIZ++ Samples  VIZ++ ClassTree 

Source code

/*
 * OpenGLStrokeFont.h 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


#pragma once

#include <viz++/opengl/OpenGLObject.h>
#include <viz++/opengl/OpenGLFont.h>

namespace VIZ {

class OpenGLStrokeFont :public OpenGLFont {

public:
  OpenGLStrokeFont(void* font = GLUT_STROKE_ROMAN)
  :OpenGLFont(font)
  {
     if (validate(font) == false) {
       throw IException("Invalid font");
     }
  }

  virtual bool validate(void* font)
  {
     // See /usr/include/GL/freeglut_std.h
     void* fonts[] = {
       GLUT_STROKE_ROMAN,               
       GLUT_STROKE_MONO_ROMAN,        
     };
     bool rc = false;
     for (int i = 0; i<CountOf(fonts); i++) {
       if (font == fonts[i]) {
         rc = true;
         break;
       }
     }
    return rc;
  }

  void strokeCharacter(int character)
  {
    glutStrokeCharacter(getFont(), character);
  }

  int  strokeWidth( int character)
  {
    return glutStrokeWidth(getFont(), character);
  }
 
  int  strokeLength(const unsigned char* string)
  {
    return glutStrokeLength(getFont(), string);
  }

  void drawString(const char* string)
  {
    if (string) {
      size_t len = strlen(string);
      for (size_t i = 0; i < len; i++) {
        strokeCharacter(string[i]);
      }
    }
  }
};

}


Last modified: 10 Feb 2017

Copyright (c) 2009-2017 Antillia.com ALL RIGHTS RESERVED.