// Computergrafik I // Prof. Dr. Juergen Doellner // Sommersemester 2001 // // Programmrahmen fuer Aufgabe 4 #ifndef CG_APPLICATION_H #define CG_APPLICATION_H // to use the OpenGL Utility Library #include class CGApplication { public: // This abstract base class provides a frame set to solve // your exercises. For that purpose the virtual on*-methods // below should be overwritten. // This class is a "singleton", so there can be only one instance // at a time. CGApplication(); virtual ~CGApplication(); // Starts the application and initializes glut. // This method should be invoked from within the main function. // The default parameters are a string variable to name the window, // a boolean flag to allow double-buffering and // two integer values to define the window dimensions. void start(const char* windowTitle = "CGApplication", bool doubleBuffering = true, int windowWidth = 400, int windowHeight = 400); // This method will be invoked only once during the initialization // process to initialize OpenGL (e.g., to specify the background color // of the window). // This method may be overwritten by a derived class. virtual void onInit(); // This method must be invoked whenever the content // of a window needs to be redrawn. // The pure virtual method must be overwritten by a derived class! virtual void onDraw() = 0; // This method will be invoked whenever the window size has been changed. // Additionally, the onDraw() method will be invoked implicitly. // The pure virtual method must be overwritten by a derived class! virtual void onSize(int newWidth, int newHeight) = 0; // Constant values indicating the left and right mouse button. enum MouseButton { LeftMouseButton, RightMouseButton }; // This method will be invoked whenever a mouse button has been pressed // within the window area. The parameter button indicates which button has been // pressed. The parameters x and y provide window coordinates in pixels. // The origin is located in the lower left corner of the window. // This method may be overwritten by a derived class. virtual void onButton(MouseButton button, int x, int y); // This method will be invoked whenever a mouse pointer has been moved // within the window area. The parameters x and y provide window // coordinates in pixel. // The origin is located in the lower left corner of the window. // This method may be overwritten by a derived class. virtual void onMove(int x, int y); // This method will be invoked whenever a key has been pressed. // The parameter key is the generated ASCII value. // This method may be overwritten by a derived class. virtual void onKey(unsigned char key); // This method should be invoked whenever drawing is made (e.g. finishing the // onDraw()-method) to swap front- and backbuffer and to make changes visible. void swapBuffers(); private: // This class is a singleton and must not be copied. // Copy constructor and assignment operator are prohibited. CGApplication(const CGApplication&); CGApplication& operator=(const CGApplication&); }; #endif // CG_APPLICATION_H