/************************************************************************ File: simple2.cpp Author: Michael L Gleicher, gleicher@cs.wisc.edu Modifier Yu-Chi Lai, yu-chi@cs.wisc.edu Comment: written 10/16/99, Michael L Gleicher For demoing the basic operation in OpenGL Platform: Visio Studio.Net 2003 *************************************************************************/ #include #include #include #include #include #include // make a Gl window that draws something: class MyGlWindow : public Fl_Gl_Window { public: float r,g,b; MyGlWindow(int x, int y, int w, int h) : Fl_Gl_Window(x,y,w,h,"My GL Window") { r = g = 1; b = 0; } private: void draw() { // the draw method must be private glMatrixMode(GL_PROJECTION); // set up coord system glLoadIdentity(); // reset it glOrtho(-1,1,-1,1,-1,1); // set it to be -1 to 1 in each axis glMatrixMode(GL_MODELVIEW); // back to normal mode glLoadIdentity(); // clear what anyone else did glClearColor(0,0,0,0); // clear the window to black glClear(GL_COLOR_BUFFER_BIT); // clear the window glColor3f(r,g,b); // draw in yellow glRectf(-.5,-.5,.5,.5); // draw a filled rectangle }; }; //******************************************************************************** // // * A simple callback to do something //================================================================================ void changeColor(Fl_Widget* /*button*/, MyGlWindow* myWind) //================================================================================ { myWind->r = 1 - myWind->r; myWind->g = 1 - myWind->g; myWind->b = 1 - myWind->b; myWind->damage(1); } // the main routine makes the window, and then runs an even loop // until the window is closed main() { Fl_Double_Window* wind = new Fl_Double_Window(100,100,400,300,"GL Sample"); wind->begin(); // put widgets inside of the window MyGlWindow* gl = new MyGlWindow(10,10,280,280); Fl_Button* bt = new Fl_Button(300,10,70,25,"Color"); bt->callback((Fl_Callback*) changeColor, gl); wind->end(); wind->show(); // this actually opens the window Fl::run(); delete gl; return 1; }