VIZ++ Class: OpenGLProfile

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

Source code

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


#pragma once

#include <viz++/ModuleFileName.h>
#include <viz++/opengl/OpenGLObject.h>
#include <viz++/StringT.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <share.h>

namespace VIZ {

class OpenGLProfile : public OpenGLObject {
private:
  char  defaultProfile[MAX_PATH];
  int   majorVersion; 
  int   minorVersion;
  
public:
  OpenGLProfile()
  :OpenGLObject(),
  majorVersion(INVALID_VALUE),
  minorVersion(INVALID_VALUE)
  {
    ModuleFileName moduleFileName;
    const char* drive = moduleFileName.getDrive();
    const char* dir   = moduleFileName.getDir();
    static const char* DEFAULT_PROFILE = "oglprofile.ogl";  
    //The DEFAULT_PROFILE should be in the current program (.exe) module folder.
    sprintf_s(defaultProfile, sizeof(defaultProfile),  "%s%s%s", drive, dir, DEFAULT_PROFILE);
    
  }
  
  bool exists()
  {
    //struct stat st;
    struct _stat64i32 st;
    //
    int r = _stat(defaultProfile, &st);
    if (r == -1 && errno == ENOENT) {
      return false;
    } else {
      return true;
    }
  }
  
  
  void read()
  {
    FILE* fp = _fsopen(defaultProfile, "r",  _SH_DENYNO);
    if (fp) {
      char line[1024];
      while(fgets(line, sizeof(line), fp)) {
        StringT<char> aline(line);
        aline.trim();
        if (aline.startsWith("//")) {
          //MessageBox(NULL, line, "Comment", MB_OK);
          continue;
        }
        const char* equal = strstr(line, "=");
        if (equal) {
          int tlen = strlen(line);
          line[tlen] = ZERO;
          line[(int)(equal-line)] = ZERO;
          StringT<char> name(line);
          StringT<char> value(equal+1);
          name.trim();
          value.trim();
          if (name == "majorVersion") {
            majorVersion = atoi((const char*)value);
          }
          if (name ==  "minorVersion") {
            minorVersion = atoi((const char*)value);
          }
        }
      }
      fclose(fp);    
    }
  }
  
  int getMajorVersion()
  {
    return majorVersion;
  }
  
  int getMinorVersion()
  {
    return minorVersion;
  }

};

}

      

Last modified: 10 Feb 2017

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