File: imagehandler.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 (99 lines) | stat: -rw-r--r-- 2,485 bytes parent folder | download | duplicates (2)
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
#include <string.h>

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

#include "main/imagehandler.h"
#include "../exception.h"
#include "../demolib_prefs.h"
#include "opengl/texture.h"

#if DEMOLIB_MAINLOOP 

ImageHandler::ImageHandler(MainLoop *ml, const char *title, const char *elem, Hashtable *attr) :
	Event(ml, title, elem, attr, "xcsize:ycsize:xpos:ypos:xsize:ysize:alpha")
{
	this->tex = texture::load(attr->get_str("file"));
}
ImageHandler::~ImageHandler()
{
	texture::free(this->tex);
	this->tex = NULL;
}

void ImageHandler::start_effect()
{
}

void ImageHandler::draw_scene(float progress)
{
	float alpha = this->get_val("alpha", progress);
	if (alpha <= 0.0f) return;

	float xcsize = this->get_val("xcsize", progress);
	float ycsize = this->get_val("ycsize", progress);
	float xpos = this->get_val("xpos", progress) - xcsize * 0.5f;
	float ypos = this->get_val("ypos", progress) - ycsize * 0.5f;
	float xsize = this->get_val("xsize", progress) + xcsize;
	float ysize = this->get_val("ysize", progress) + ycsize;

        glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
	glLoadIdentity();

	glScalef(DEMOLIB_YASPECT / DEMOLIB_XASPECT, 1.0f, 1.0f);

        glMatrixMode(GL_PROJECTION);
        glPushMatrix();
        glLoadIdentity();

	glOrtho(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

        glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glDisable(GL_STENCIL_TEST);
	
	this->tex->bind();
        glEnable(GL_TEXTURE_2D);

        glColor4f(1.0f, 1.0f, 1.0f, alpha);
	
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	float w_nudge = 0.5f / (float)tex->get_width();
	float h_nudge = 0.5f / (float)tex->get_height();
	
        glBegin(GL_QUADS);

        glTexCoord2f(w_nudge, h_nudge);
        glVertex3f(xpos, ypos, 0.0f);

        glTexCoord2f(w_nudge, 1.0f - h_nudge);
        glVertex3f(xpos, ypos + ysize, 0.0f);

        glTexCoord2f(1.0f - w_nudge, 1.0f - h_nudge);
        glVertex3f(xpos + xsize, ypos + ysize, 0.0f);

        glTexCoord2f(1.0f - w_nudge, h_nudge);
        glVertex3f(xpos + xsize, ypos, 0.0f);

        glEnd();

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

	glPopMatrix();

	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
}

void ImageHandler::end_effect() {}

#endif