VIZ++ Class: OpenGLTexturedCube

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

Source code

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

 
#pragma once

#include <viz++/opengl/OpenGLTexture2D.h>
#include <viz++/opengl/TextureCoord2Vertex3.h>
#include <viz++/opengl/TextureCoordTriangularCube.h>

namespace VIZ {

class OpenGLTexturedCube : public OpenGLTexture2D {
private:
  TextureCoordTriangularCube* ttc;
  
public:
  OpenGLTexturedCube(GLfloat size=1.0f)
  :OpenGLTexture2D(),
  ttc(NULL)
  {
    ttc = new TextureCoordTriangularCube(size);
  }

public:
  OpenGLTexturedCube(const char* filename, GLfloat size=1.0f)
  :OpenGLTexture2D(),
  ttc(NULL)
  {
    ttc = new TextureCoordTriangularCube(size);
    
    load(filename);
  }

  ~OpenGLTexturedCube()
  {
    delete ttc;
    ttc = NULL;
  }
  
  virtual void load(const char* filename)
  {
    bind();

    pixelStore(GL_UNPACK_ALIGNMENT, 4);
    
    parameter(GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    parameter(GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    env(GL_TEXTURE_ENV_MODE, GL_MODULATE);
  
    generate(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
    generate(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);

    parameter(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    parameter(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
    try {
      imageFromFile(filename);
    } catch (Exception& ex) {
      ex.display();
    }
    
    unbind();
  }
  
    
  public:
    virtual void draw(OpenGLGC* gc)
    {      
      TextureCoord2Vertex3* cube = ttc->getData();
      
      int numElements = ttc->getNumberOfElements();
      
      if (gc) {
        bind();
        
        gc -> enable(GL_NORMALIZE);
       
        gc -> begin(GL_TRIANGLES);
        
        for (int i = 0; i<numElements; i++) {
          coordVertex(cube[i]);
        }
        gc -> end();
        unbind();
      }
    }
 
 };
}
 

Last modified: 10 Feb 2017

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