File: demohandler.cpp

package info (click to toggle)
amoeba 1.1-13
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 732 kB
  • ctags: 971
  • sloc: cpp: 8,315; makefile: 178
file content (120 lines) | stat: -rw-r--r-- 2,715 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#ifdef __linux__
#include <X11/keysym.h>
#endif

#include "main/demohandler.h"
#include "opengl/glwindow.h"
#include "../exception.h"
#include "../demolib_prefs.h"

#if DEMOLIB_MAINLOOP 

DemoHandler::DemoHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) :
	Event(ml, title, elem, attr, NULL)
{
	this->ml = ml;
	this->layer = -1000.0f;

	bool fullscreen = attr->get_bool("fullscreen");

	/*
	 * It's extremely important that this comes HERE and not in
	 * start_effect()! Otherwise, other constructors doing OpenGL
	 * commands (textures, for instance) would fail and mess
	 * everything up quite badly...
	 */
	int xres = attr->get_int("xres");
	int yres = attr->get_int("yres");

	if (attr->exists("visual_id")) {
		this->win = new GLWindow(this->title, xres, yres, -1,
			fullscreen, -1, attr->get_int("visual_id"));
		return;
	}
		
	int bpp = attr->get_int("depth");
	int zbpp = attr->get_int("zbuffer");
	this->win = new GLWindow(this->title, xres, yres, bpp,
		fullscreen, zbpp, -1);

}
DemoHandler::~DemoHandler()
{
	delete this->win;
	this->win = NULL;
}

void DemoHandler::start_effect()
{
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glShadeModel(GL_SMOOTH);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
        glDepthFunc(GL_LESS);

	while (this->active) {
#ifdef __linux__
		/*
		 * Linux doesn't use a message queue like Win32, so we'll
		 * handle X events here :-)
		 */
		while (XPending(this->win->dpy) > 0) {
			XEvent event;
			XNextEvent(this->win->dpy, &event);

			switch (event.type) {
			case ConfigureNotify:
                		if ((event.xconfigure.width != (signed int)this->win->width) || 
				    (event.xconfigure.height != (signed int)this->win->height)) {
					this->win->width = event.xconfigure.width;
					this->win->height = event.xconfigure.height;
					this->win->resize(0, 0, this->win->width, this->win->height);
				}
				break;
	            	case ButtonPress:   
				this->win->done = true;
				break;
			case KeyPress:
				if (XLookupKeysym(&event.xkey, 0) == XK_Escape) {
					this->win->done = true;
				}
		                break;
			}
		}
#endif

		this->ml->run(false);
		this->win->flip();

		if (this->win->is_done()) {
			this->end_effect();	
		}
	}
}

void DemoHandler::draw_scene(float progress)
{
}

void DemoHandler::end_effect()
{
	this->active = false;

	/* end everything, MainLoop will clean it up */
	for (int i = 0; i < this->ml->num_events; i++) {
		Event *e = this->ml->events[i];
		if (e && e->active && e != this) {
#if !DEMOLIB_SILENT
			printf("Exiting: %s\n", e->title);
#endif

			e->end_effect();
			e->active = false;
		}
	}
}

#endif