SOL9 Sample: Version

SOL9 2.0 Samples

1 Screenshot


2 Source code

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


//2015/07/24 A creation of OpenGLOutlineFont for "Courier" font seems to fail?

#include <sol/opengl/OpenGLMainView.h>
#include <sol/opengl/OpenGLView.h>
#include <sol/opengl/OpenGLOutlineFont.h>

#include <sol/opengl/OpenGLGC.h>

namespace SOL {

class MainView :public OpenGLMainView {

private:
  //Inner class starts.
  class SimpleView :public OpenGLView {
  private:
    SmartPtr<OpenGLGC>          gc;
    SmartPtr<Font>              arial;
    SmartPtr<OpenGLOutlineFont> arialFont;
    SmartPtr<Font>              times;
    SmartPtr<OpenGLOutlineFont> timesFont;
    
  public:
    virtual void display()
    {
      if (gc && arialFont && timesFont) {
        ClientDC* cdc = getClientDC();
      
        GLfloat angle = 0.0;
        gc -> clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
        gc -> scale(0.4, 0.4, 0.4);
        gc -> rotate(angle, 0, 0, 1.0);

        gc -> backgroundColor(0.0, 0.0, 0.0, 1.0);
        const char* version = (const char*)glGetString(GL_VERSION);
        
        gc -> pushMatrix();
        gc -> rotate(angle+10, 0.0, 0.0, 1.0);
        gc -> translate(-10.0, 4.0, 0.0);
        gc -> foregroundColor(1.0, 0.0, 0.0);
        arialFont -> drawString(cdc, version);
        gc -> popMatrix();
  
        gc -> pushMatrix();
        gc -> rotate(angle, 0.0, 0.0, 1.0);
        gc -> translate(-10.0, 0.0, 0.0);
        gc -> foregroundColor(0.0, 1.0, 0.0);
        arialFont -> drawString(cdc, version);
        gc -> popMatrix();

        gc -> pushMatrix();
        gc -> rotate(angle-10, 0.0, 0.0, 1.0);
        gc -> translate(-10.0, -4.0, 0.0);
        gc -> foregroundColor(0.0, 0.0, 1.0);
        timesFont -> drawString(cdc, version);
        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();
      }
    }

   void createArialFont(ClientDC* cdc, int pointSize)
    {
      int logPixel = cdc -> getDeviceCaps(LOGPIXELSY);

      int nHeight = -MulDiv(pointSize, logPixel, 72); 
      Args ar;
      ar.set(XmNheight, nHeight);
      ar.set(XmNweight,  FW_NORMAL);
      ar.set(XmNcharSet, ANSI_CHARSET);
      ar.set(XmNfaceName, "Arial");
      arial = new Font(ar);
      arialFont = new OpenGLOutlineFont(cdc, arial);
    }

    void createTimesFont(ClientDC* cdc, int pointSize)
    {
      int logPixel = cdc -> getDeviceCaps(LOGPIXELSY);

      int nHeight = -MulDiv(pointSize, logPixel, 72); 
      Args ar;
      ar.set(XmNheight, nHeight);
      ar.set(XmNweight,  FW_NORMAL);
      ar.set(XmNcharSet, ANSI_CHARSET);
      ar.set(XmNfaceName, "Times New Roman");
      times = new Font(ar);
      timesFont = new OpenGLOutlineFont(cdc, times);
    }
    
    virtual void initialize()
    {
      ClientDC* cdc = getClientDC();
      
      createArialFont(cdc, 24);
      createTimesFont(cdc, 24);

      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);
    }
    
  public:
    SimpleView(View* parent, const char* name, Args& args)
    :OpenGLView(parent, name, args)
    {
    }
 
    ~SimpleView()
    {
    }
  };
  //Inner class ends.

private:
  SmartPtr<SimpleView> view;

  long size(Event& event)
  {
    int w, h;
    event.getSize(w, h);
    if (view) {
      view -> reshape(10, 10, w-20, h-20);
      view -> postResizeRequest(w-20, h-20);
    }
    return 0L;
  }

public:
  MainView(Application& applet, const char* name, Args& args)
  :OpenGLMainView(applet, name, args)
  {
    Args ar;
    view = new SimpleView(this, "", ar);
  }
  
  ~MainView()
  {
  }
};
}

//
void Main(int argc, char** argv)
{
  try {

    const char*  name = appName(argv[0]);
    Application applet(name, argc, argv);
    Args args;
    args.set(XmNwidth, 800);
    args.set(XmNheight, 400);
    MainView view(applet, name, args);
    view.realize();

    applet.run();
    
  } catch (Exception& ex) {
    ex.show();
    
  }
}


Last modified: 25 Feb 2017

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