1 // Computergrafik I
2 // Prof. Dr. Juergen Doellner
3 // Sommersemester 2001
4 //
5 // Programmrahmen fuer Aufgabe 4
6
7 #ifndef CG_APPLICATION_H
8 #define CG_APPLICATION_H
9
10 // to use the OpenGL Utility Library
11 #include <GL/glut.h>
12
13 class CGApplication {
14 public:
15 // This abstract base class provides a frame set to solve
16 // your exercises. For that purpose the virtual on*-methods
17 // below should be overwritten.
18 // This class is a "singleton", so there can be only one instance
19 // at a time.
20 CGApplication();
21 virtual ~CGApplication();
22
23 // Starts the application and initializes glut.
24 // This method should be invoked from within the main function.
25 // The default parameters are a string variable to name the window,
26 // a boolean flag to allow double-buffering and
27 // two integer values to define the window dimensions.
28 void start(const char* windowTitle = "CGApplication",
29 bool doubleBuffering = true,
30 int windowWidth = 400, int windowHeight = 400);
31
32 // This method will be invoked only once during the initialization
33 // process to initialize OpenGL (e.g., to specify the background color
34 // of the window).
35 // This method may be overwritten by a derived class.
36 virtual void onInit();
37
38 // This method must be invoked whenever the content
39 // of a window needs to be redrawn.
40 // The pure virtual method must be overwritten by a derived class!
41 virtual void onDraw() = 0;
42
43 // This method will be invoked whenever the window size has been changed.
44 // Additionally, the onDraw() method will be invoked implicitly.
45 // The pure virtual method must be overwritten by a derived class!
46 virtual void onSize(int newWidth, int newHeight) = 0;
47
48 // Constant values indicating the left and right mouse button.
49 enum MouseButton { LeftMouseButton, RightMouseButton };
50
51 // This method will be invoked whenever a mouse button has been pressed
52 // within the window area. The parameter button indicates which button has been
53 // pressed. The parameters x and y provide window coordinates in pixels.
54 // The origin is located in the lower left corner of the window.
55 // This method may be overwritten by a derived class.
56 virtual void onButton(MouseButton button, int x, int y);
57
58 // This method will be invoked whenever a mouse pointer has been moved
59 // within the window area. The parameters x and y provide window
60 // coordinates in pixel.
61 // The origin is located in the lower left corner of the window.
62 // This method may be overwritten by a derived class.
63 virtual void onMove(int x, int y);
64
65 // This method will be invoked whenever a key has been pressed.
66 // The parameter key is the generated ASCII value.
67 // This method may be overwritten by a derived class.
68 virtual void onKey(unsigned char key);
69
70 // This method should be invoked whenever drawing is made (e.g. finishing the
71 // onDraw()-method) to swap front- and backbuffer and to make changes visible.
72 void swapBuffers();
73
74 private:
75 // This class is a singleton and must not be copied.
76 // Copy constructor and assignment operator are prohibited.
77 CGApplication(const CGApplication&);
78 CGApplication& operator=(const CGApplication&);
79 };
80
81 #endif // CG_APPLICATION_H
82
83