File: foghandler.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 (54 lines) | stat: -rw-r--r-- 1,011 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
#include <string.h>
#include <math.h>
#include <stdlib.h>

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>

#include "main/foghandler.h"
#include "exception.h"
#include "demolib_prefs.h"

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502
#endif

#if DEMOLIB_MAINLOOP 

FogHandler::FogHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) :
		Event(ml, title, elem, attr, "start:end:r:g:b:a")
{
}

FogHandler::~FogHandler()
{
}

void FogHandler::start_effect()
{
	glEnable(GL_FOG);
	glHint(GL_FOG_HINT, GL_FASTEST);
	glFogi(GL_FOG_MODE, GL_LINEAR);
}

void FogHandler::draw_scene(float progress)
{
	GLfloat fog_color[] = {
		this->get_val("r", progress),
		this->get_val("g", progress),
		this->get_val("b", progress),
		this->get_val("a", progress)
	};
	glFogf(GL_FOG_START, this->get_val("start", progress));
	glFogf(GL_FOG_END,   this->get_val("end", progress));
	glFogfv(GL_FOG_COLOR, fog_color);
}

void FogHandler::end_effect()
{
	glDisable(GL_FOG);
}

#endif