sources:
BOX.CPP (3.1k)
BOX.H (507 bytes)
RAY.CPP (609 bytes)
RAY.H (604 bytes)
SPHERE.CPP (1.9k)
SPHERE.H (564 bytes)
TRIANGLE.CPP (2.1k)
TRIANGLE.H (1.2k)
UTIL.H (1.7k)
VECTOR.CPP (1.6k)
VECTOR.H (5.0k)
cgapplication.cpp (3.2k)
cgapplication.h (3.5k)
cgraytracer.cpp (18.8k)
cgraytracer.h (1.6k)
shape.h (754 bytes)


binaries:
Release/raytracer.exe (38.0k)


website:
more info here


screenshot:
studies/grafik2/Computergrafik-Code6/Aufgabe17/cgapplication.cpp
download file

  1 //
  2 // Computergraphik II
  3 // Prof. Dr. Juergen Doellner
  4 // Wintersemester 2001/02
  5 //
  6 // Rahmenprogramm zu Aufgabenzettel 7
  7 //
  8
  9 #include "cgapplication.h"
 10
 11 // Diese Variable enthaelt einen Zeiger auf die aktive Anwendung.
 12 static CGApplication* activeApplication_ = 0;
 13
 14 CGApplication::CGApplication() {
 15     assert(!activeApplication_); // Es ist nur eine aktive Anwendung erlaubt!!!
 16     activeApplication_ = this;
 17 }
 18
 19 CGApplication::~CGApplication() {
 20     activeApplication_ = 0;
 21 }
 22
 23 // Auf diese Ereignisse wird default-maessig nicht reagiert:
 24 void CGApplication::onInit() { }
 25 void CGApplication::onButton(MouseButton button, int x, int y) { }
 26 void CGApplication::onMove(int x, int y) { }
 27 void CGApplication::onKey(unsigned char key) { }
 28 void CGApplication::onIdle() { }
 29
 30 // glut-Callback fuer den Zeichenaufruf
 31 static void displayFunc() {
 32     assert(activeApplication_);
 33     activeApplication_->onDraw();
 34 }
 35
 36 // glut-Callback fuer die Aenderung der Fenstergroesse
 37 static void reshapeFunc(int newWidth, int newHeight) {
 38     assert(activeApplication_);
 39     activeApplication_->onSize(newWidth, newHeight);
 40 }
 41
 42 // glut-Callback fuer das Druecken einer Maustaste
 43 static void mouseFunc(int button, int state, int x, int y) {
 44     assert(activeApplication_);
 45     if(state == GLUT_DOWN) {
 46         y = glutGet(GLenum(GLUT_WINDOW_HEIGHT)) - y; // Koordinaten-Ursprung: links unten!!!
 47         if(button == GLUT_LEFT_BUTTON) {
 48             activeApplication_->onButton(CGApplication::LeftMouseButton, x, y);
 49         } else {
 50             activeApplication_->onButton(CGApplication::RightMouseButton, x, y);
 51         }
 52     }
 53 }
 54
 55 // glut-Callback fuer das Ziehen bei gedrueckter Maustaste
 56 static void motionFunc(int x, int y) {
 57     assert(activeApplication_);
 58     y = glutGet(GLenum(GLUT_WINDOW_HEIGHT)) - y; // Koordinaten-Ursprung: links unten!!!
 59     activeApplication_->onMove(x, y);
 60 }
 61
 62 // glut-Callback fuer einen Tastendruck
 63 static void keyboardFunc(unsigned char key, int x, int y) {
 64     assert(activeApplication_);
 65     activeApplication_->onKey(key);
 66 }
 67
 68
 69 // glut-Callback fuer einen Tastendruck
 70 static void idleFunc() {
 71     assert(activeApplication_);
 72     activeApplication_->onIdle();
 73 }
 74 void CGApplication::start(const char* windowTitle, bool doubleBuffering,
 75                           unsigned long width, unsigned long height)
{
 76     // Fordert ein OpenGL-Fenster im RGB-Format mit oder ohne Double-Buffering an:
 77     glutInitDisplayMode(GLUT_RGB | (doubleBuffering ? GLUT_DOUBLE : GLUT_SINGLE));
 78
 79     // Legt die Fenstergroesse fest:
 80     glutInitWindowSize(width, height);
 81
 82     // Erzeugt das OpenGL-Fenster mit dem entsprechenden Namen:
 83     glutCreateWindow(windowTitle);
 84
 85     // Registriere die oben definierten Callbacks fuer die
 86     // entsprechenden glut-Ereignisse:
 87     glutDisplayFunc(displayFunc);
 88     glutReshapeFunc(reshapeFunc);
 89     glutMouseFunc(mouseFunc);
 90     glutMotionFunc(motionFunc);
 91     glutKeyboardFunc(keyboardFunc);
 92     glutIdleFunc(idleFunc);
 93
 94     // Zeige das OpenGL-Fenster auf dem Bildschirm an
 95     glutShowWindow();
 96
 97     // Rufe die Methode zur Initialisierung von OpenGL auf:
 98     onInit();
 99
100     // Starte die Verarbeitung der glut-Ereignisse:
101     glutMainLoop();
102 }
103
104 void CGApplication::swapBuffers() {
105     glutSwapBuffers();
106 }
107
108