// example file for fltk-gl // author: Matteo Lucarelli // compile with: // g++ `fltk-config --ldflags --use-gl` gl-with-fltk.cpp -o gl-with-fltk #include // on some system these are not equals #include //#include // on some system these are not equals #include //#include #include #include #include #include #include #define MAX_SIDES 100 #define MIN_SIDES 3 /////////////////////////////////////////////////////////////////////////////// // this should be in a header file class gl_frame : public Fl_Gl_Window { public: gl_frame(int x,int y,int w,int h,const char *l=0); int sides; bool grow; protected: void draw(); }; gl_frame::gl_frame(int x,int y,int w,int h,const char *l) :Fl_Gl_Window(x,y,w,h,l) { sides = 3; grow = true; } void gl_frame::draw() { if (!valid()) { valid(1); glLoadIdentity(); glViewport(0,0,w(),h()); } glClear(GL_COLOR_BUFFER_BIT); glColor3f(.5,.6,.7); glBegin(GL_POLYGON); for (int i=0; isides==MIN_SIDES) glf->grow=true; if (glf->sides==MAX_SIDES) glf->grow=false; if (glf->grow) glf->sides++; else glf->sides--; glf->redraw(); Fl::repeat_timeout((2.0/glf->sides),timer_cb,p); } void double_cb(Fl_Widget *o, void *p) { gl_frame *glf = (gl_frame*)p; glf->mode(((Fl_Button *)o)->value() ? Fl_Mode(FL_DOUBLE|FL_RGB) : FL_RGB); } /////////////////////////////////////////////////////////////////////////////// int main(int argc, char **argv) { gl_frame glf(10,10,280,280); glf.mode(FL_RGB); Fl_Single_Window window(300,330); window.add(glf); window.resizable(&glf); Fl_Toggle_Light_Button db(10,295,window.w()-20,30,"Double Buffered"); db.callback(double_cb,&glf); window.end(); window.show(argc,argv); Fl::add_timeout(2.0/3,timer_cb,&glf); return Fl::run(); }