// _prelude_ // _generic_ // _glut_ // _window_ // _editor_ // _compiler_ // _shapes_ // _graphs_ // _startup_ // _prelude_ --------------------------------------------------------- #include #include #include #include #include #include using namespace std; namespace AMPS { typedef double Num; // _generic_ --------------------------------------------------------- // base object class - not needed? class Object { public: virtual ~Object() = 0; }; inline Object::~Object() {} // _glut_ ------------------------------------------------------------ class Window; vector windows; // _window_ ---------------------------------------------------------- class Window : Object { protected: int window; int width; int height; private: // This static member 'windows' does not work for some obscure reason. // static unordered_map windows; static void static_display() { int window = glutGetWindow(); windows[window]->display(); } // static void static_timer(int window) { // windows[window]->timer(); // } public: Window(const char *title = "app", int width_ = 0, int height_ = 0, bool fullscreen = 0) : width(width_), height(height_) { if (width && height) { glutInitWindowSize(width, height); } window = glutCreateWindow(title); // cerr << "window: " << window << endl; // TODO use growvec? if (window >= (int)windows.size()) windows.resize(window+1); windows[window] = this; if (fullscreen) glutFullScreen(); glutDisplayFunc(&static_display); width = glutGet(GLUT_WINDOW_WIDTH); height = glutGet(GLUT_WINDOW_HEIGHT); } virtual ~Window() { glutDestroyWindow(window); } virtual void display() { glClear(GL_COLOR_BUFFER_BIT); glutSwapBuffers(); } void refresh() { // cerr << "refresh" << window << endl; glutPostWindowRedisplay(window); } }; // _editor_ ---------------------------------------------------------- //long long unique = 1; // //long long get_unique() { // //} class Editor : Window { public: int frame_i; Editor() : Window("AMPS", glutGet(GLUT_SCREEN_WIDTH), glutGet(GLUT_SCREEN_HEIGHT), 0), frame_i(0) { gluPerspective(30, (double)width / height, 0.1, 10); glTranslated(0, 0, -2); // gluOrtho2D(-width/2, width/2, -height/2, height/2); // TODO if need other timers, a problem! use a map? glutTimerFunc(0, static_timer_animate, window); } private: virtual void display() { // cerr << "display" << endl; glClear(GL_COLOR_BUFFER_BIT); glutWireTeapot(0.5); glutSwapBuffers(); } void animate() { // cerr << "animate" <