VIZ++ Sample: StrokeFont

VIZ++ Samples

1 Screenshot


2 Source code

/*
 * StrokeFont.cpp 
 * Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


//2017/02/10

#include <viz++/opengl/OpenGLMainView.h>

#include <viz++/opengl/OpenGLGC.h>
#include <viz++/opengl/OpenGLStrokeFont.h>

namespace VIZ {

class MainView :public OpenGLMainView {

private:
  SmartPtr<OpenGLGC>         gc;
  SmartPtr<OpenGLStrokeFont> roman;
  SmartPtr<OpenGLStrokeFont> romanmono;
  
public:
  virtual void display()
  {
    if (gc && roman && romanmono) {
    GLfloat angle = 0.0;
    gc -> matrixMode(GL_MODELVIEW);
    gc -> loadIdentity();

    gc -> scale(0.004, 0.004, 0.004);
    gc -> rotate(angle, 0, 0, 1.0);


    gc -> clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    gc -> backgroundColor(0.0, 0.0, 0.0, 1.0);
        
    gc -> pushMatrix();
    gc -> rotate(angle+10, 0.0, 0.0, 1.0);
    gc -> translate(-800.0, 300.0, 0.0);
    gc -> foregroundColor(1.0, 0.0, 0.0);
    roman -> drawString("2015/07/22 Good Day.");
    gc -> popMatrix();
  
    gc -> pushMatrix();
    gc -> rotate(angle, 0.0, 0.0, 1.0);
    gc -> translate(-900.0, 0.0, 0.0);
    gc -> foregroundColor(0.0, 1.0, 0.0);
   
    romanmono -> drawString("Hello World.");

    gc -> popMatrix();

    gc -> pushMatrix();
    gc -> rotate(angle-10, 0.0, 0.0, 1.0);
    gc -> translate(-900.0, -400.0, 0.0);
    gc -> foregroundColor(0.0, 0.0, 1.0);
   
    romanmono -> drawString("Goodby World.");

    gc -> popMatrix();
    }
  }
 
  virtual void resize(int w, int h)
  {
    if (w == 0 || h == 0) {
      return;
    }
    
    if (gc) {
      gc -> matrixMode(GL_PROJECTION); 
      gc -> loadIdentity(); 
    
      GLfloat ww = (GLfloat)w;
      GLfloat hh = (GLfloat)h;

      if (w <= h) {
        gc ->ortho(-2.0, 2.0, -2.0 * hh / ww,
            2.0 * hh / ww, -1.0, 1.0);
      } else {
        gc ->ortho(-2.0 * ww / hh,
            2.0 * ww / hh, -2.0, 2.0, -1.0, 1.0);
      }
      gc -> matrixMode(GL_MODELVIEW);
      gc -> loadIdentity();
    }
  }

  virtual void initialize()
  {
    gc = new OpenGLGC();
    gc -> matrixMode(GL_PROJECTION);
    gc -> loadIdentity();
    gc -> ortho2D(0, 2000, 2000, 0);

    gc -> matrixMode(GL_MODELVIEW);
    gc -> enable(GL_LINE_SMOOTH);
    gc -> enable(GL_BLEND);
    gc -> blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    gc -> lineWidth(3.0);
    gc -> translate(0.0, 0.0, 0.0);

    roman      = new OpenGLStrokeFont(GLUT_STROKE_ROMAN);
    romanmono = new OpenGLStrokeFont(GLUT_STROKE_MONO_ROMAN);
  }


public:
  MainView(OpenGLApplet& applet, int width, int height, const char* name)
  :OpenGLMainView(applet, width, height, name)
  {
  }
  
  ~MainView()
  {
  }
};
}

//
int main(int argc, char** argv)
{
  try {
    //Intialize glut library
    glutInit(&argc, argv);
    ModuleFileName module;
    const char*  name = module.getAppName();
    OpenGLApplet applet(argc, argv);

    MainView view(applet, 800, 400, name);
    view.realize();
    applet.run();
    
  } catch (Exception& ex) {
    caught(ex);
  }
  return 0;
}


Last modified: 10 Feb 2017

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