www.pudn.com > fi_treegen10.zip > graphics.h


//---------------------------------------------------------------------------
// graphics.h: interface for the OGL_Window class.
// by Alex ( alex@FusionIndustries.com ) 
// 
// This code may be freely used in any project, as long as credit 
// or greetz are given. Please also let me know if you use this 
// code, find it useful, or even if you don't like it. 
//--------------------------------------------------------------------------- 
#include "global.h" 
#include 
#include  
#include  
#include  
#include  
#include "Tree.h" 
 
#include  
#include  
#include  
#include  
 
#define ORTHOMODE 0 
#define PROJMODE  1 
 
//--------------------------------------------------------------------------- 
class OGL_Window : public Fl_Gl_Window 
{
  public:
    void quit();
    OGL_Window(int x, int y, int w, int h, const char *l = 0);
    virtual ~OGL_Window();
    void draw();
    void init(); 

  private: 
    bool initialized; 
    int  handle(int event);
    void draw_scene();
    void drawBox( int x1, int y1, int x2, int y2, GLenum opcode ); 

  public:
    float LEFT, RIGHT, BOTTOM, TOP, FRONT, BACK; // along x x y y z z 
    float NEARCLIP; 
    float FARCLIP; 
 
  public: 
    Tree tree; 
    unsigned int recDepth; 
 
  // Drawing states 
  public: 
    bool showWorldAxis; // true ==> draw the axis 
    void toggleWorldAxis() { showWorldAxis = !showWorldAxis; draw(); } 
 
    GLenum polymode; // GL_LINE or GL_FILL 
    void togglePolyMode() { if( polymode == GL_LINE ) {polymode = GL_FILL;} 
                            else                      {polymode = GL_LINE;} 
                            glPolygonMode( GL_FRONT_AND_BACK, polymode ); 
                            draw();} 
    bool viewMode; // can be: ORTHOMODE, PROJMODE 
    void toggleProjMode() { viewMode = !viewMode; resize(w(),h()); draw(); } 
 
    void toggleTextures() 
    { 
      if( glIsEnabled(GL_TEXTURE_2D) ) 
      { 
        glDisable( GL_TEXTURE_2D ); 
        glDisable( GL_TEXTURE_GEN_S ); 
        glDisable( GL_TEXTURE_GEN_T ); 
      } 
      else 
      { 
        glEnable( GL_TEXTURE_2D ); 
        glEnable( GL_TEXTURE_GEN_S ); 
        glEnable( GL_TEXTURE_GEN_T ); 
        glTexGend( GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); 
        glTexGend( GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP ); 
      } 
      draw(); 
    } 
    void resize( GLsizei w, GLsizei h ); 
    void drawWorldAxis(); 
    void resetScene(); 
 
  // keep track of the global transforms for the scene 
  private: 
    float xrot,yrot,zrot; // rotations 
    float xpos,ypos,zpos; // translations from (0,0,0) 
    float scale;          // used uniformly as the xyz 
 
  public: 
    void setGlobalRotationX( float currXrot ) { xrot = currXrot; } 
    void setGlobalRotationY( float currYrot ) { yrot = currYrot; } 
    void setGlobalRotationZ( float currZrot ) { zrot = currZrot; } 
    void setGlobalPosX( float currXpos ) { xpos = currXpos; } 
    void setGlobalPosY( float currYpos ) { ypos = currYpos; } 
    void setGlobalPosZ( float currZpos ) { zpos = currZpos; } 
    void setGlobalScale( float currScale ) { scale = currScale; } 
};
 
//-- E O F ------------------------------------------------------------------