// nUtil - An utility Library for gnurbs
// Copyright (C) 2008-2026 Eric Bechet
//
// See the LICENSE file for contributions and license information.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//

#ifndef __NGLWINDOW_H
#define __NGLWINDOW_H

#include "fltkdisplay.h"
#include <cstring>
#include <iostream>
#include <FL/Fl.H>
#include <FL/Fl_Gl_Window.H>
#ifdef WIN32
#include "windows.h"
#endif //WIN32
#include <GL/gl.h>

typedef color ncolor; // unfortunately, "color" already exists inside Fl_Gl_Window...


class nglwindow : public Fl_Gl_Window
{
public:
  nglwindow ( int x, int y, int w, int h,ncolor _c, ngldraw *_caller): Fl_Gl_Window ( x,y,w,h ),c(_c),caller(_caller), 
                                                                           lens(4.326661531),focal(2.8),fov(( lens/2/focal ) * 2 * 180 / 3.14159265),nearclip(0.1),farclip(40.)
                                                                           
                                                                           {vp[0]=1.0;vp[1]=2.2;vp[2]=2.0; look[0]=0.;look[1]=0.;look[2]=0.;up[0]=0.; up[1]=1.;up[2]=0.;}
  virtual ~nglwindow() {}
  virtual void set_view (double lens_,double focal_, double fov_,double nearclip_,double farclip_,const double vp_[3],const double look_[3],const double up_[3]);
  virtual void set_view (void);
  virtual void print_info ( void ) {}
  virtual void draw_model ( void ); // called automatically at every refresh
  virtual void add_lights ( void );
  virtual void get_matrices ( void );
  virtual bool get_coords ( GLfloat i,GLfloat j, npoint3 &p,npoint3 &v,GLfloat &z); // computes 3D coordinates from a point picked in screen
  virtual bool get_coords ( GLfloat di,GLfloat dj,GLfloat z, npoint3 &p); //  computes 3D coordinates from a point picked in screen after drag (z given)
private:
  virtual void draw ( void ) ; // called from fltk upon redraw
  virtual void resize ( int X,int Y,int W,int H ) // called from fltk at every resize
  {
    Fl_Gl_Window::resize ( X,Y,W,H );
  }
  virtual int handle ( int event ); // called from fltk : event handling proc
  double lens;
  double focal;
  double fov;
  double nearclip;
  double farclip;
  GLdouble vp[3];
  GLdouble look[3];
  GLdouble up[3];
  GLdouble ProjectionMatrix[4][4];
  GLdouble ModelViewMatrix[4][4];
  GLdouble Inv[4][4];
  GLint Viewport[4];
  ncolor c;
  ngldraw *caller;
  bool push;
  int xp,yp;
  GLfloat z;
  double dinit;
  npoint3 orig;
};



#endif // __NGLWINDOW_H