VIZ++ Sample: Version

VIZ++ Samples

1 Screenshot


2 Source code

/*
 * Version.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/OpenGLBitmapFont.h>
#include <viz++/Callback.h>

namespace VIZ {

class MainView :public OpenGLMainView {

private:
  SmartPtr<OpenGLGC>         gc;
  int width;
  int height;
  SmartPtr<OpenGLBitmapFont> font;      //GLUT_BITMAP_9_BY_15
  SmartPtr<OpenGLBitmapFont> helvetica; //GLUT_BITMAP_HELVETICA_18
  SmartPtr<OpenGLBitmapFont> timesRoman;//GLUT_BITMAP_TIMES_ROMAN_24

public:
  virtual void display()
  {    
    if (gc && helvetica && timesRoman) {
      gc -> matrixMode(GL_PROJECTION);

      gc -> loadIdentity();
      gc -> ortho2D(0, width, height, 0);
      gc -> matrixMode(GL_MODELVIEW);
      gc -> loadIdentity();

      gc -> clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

      gc -> backgroundColor(0.0, 0.0, 0.0, 1.0);
      const char* version = (const char*)glGetString(GL_VERSION);

      gc -> pushMatrix();
      gc -> foregroundColor(1.0, 0.0, 0.0);
      font -> drawString(20, 40, version);
      gc -> popMatrix();

      gc -> pushMatrix();
      gc -> foregroundColor(0.0, 1.0, 0.0);

      helvetica -> drawString(20, 100, version);
      gc -> popMatrix();

      gc -> pushMatrix();
      gc -> foregroundColor(0.0, 0.0, 1.0);

      timesRoman -> drawString(20, 160, version);
      gc -> popMatrix();      
    }
  }
  
  virtual void resize(int w, int h)
  {
    if (w == 0 || h == 0) {
          return;
    }
    if (gc) {
       gc -> matrixMode(GL_PROJECTION);
       gc -> loadIdentity();
       gc -> matrixMode(GL_MODELVIEW);
    }
  }

  virtual void initialize()
  {
    gc = new OpenGLGC();

    gc -> matrixMode(GL_PROJECTION);
    gc -> loadIdentity();
      //gc -> ortho2D(0, width, height, 0);

    gc -> matrixMode(GL_MODELVIEW);
    gc -> enable(GL_LINE_SMOOTH);
    gc -> enable(GL_BLEND);
    gc -> blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
    font       = new OpenGLBitmapFont(GLUT_BITMAP_9_BY_15);
    helvetica  = new OpenGLBitmapFont(GLUT_BITMAP_HELVETICA_18);
    timesRoman = new OpenGLBitmapFont(GLUT_BITMAP_TIMES_ROMAN_24);
  }

 
public:
  MainView(OpenGLApplet& applet, int width, int height, const char* name)
  :OpenGLMainView(applet, width, height, name)
  {
    this -> width = width;
    this -> height = height;
  }
  
  ~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, 400, 300, 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.