textures, overlay images, libimago
[demo_prior] / src / post.c
1 #include "opengl.h"
2 #include "texture.h"
3 #include "post.h"
4 #include "demo.h"
5
6 void overlay(unsigned int tex, float aspect, float alpha)
7 {
8         float xscale = aspect / win_aspect;
9
10         glMatrixMode(GL_MODELVIEW);
11         glPushMatrix();
12         glLoadIdentity();
13         glMatrixMode(GL_PROJECTION);
14         glPushMatrix();
15         glLoadIdentity();
16         glScalef(xscale, 1.0, 1.0);
17
18         glPushAttrib(GL_ENABLE_BIT);
19         glDisable(GL_DEPTH_TEST);
20         glDisable(GL_LIGHTING);
21         glEnable(GL_BLEND);
22         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
23         glEnable(GL_TEXTURE_2D);
24
25         glBindTexture(GL_TEXTURE_2D, tex);
26
27         glBegin(GL_QUADS);
28         glColor4f(1, 1, 1, alpha);
29         glTexCoord2f(0, 1);
30         glVertex2f(-1, -1);
31         glTexCoord2f(1, 1);
32         glVertex2f(1, -1);
33         glTexCoord2f(1, 0);
34         glVertex2f(1, 1);
35         glTexCoord2f(0, 0);
36         glVertex2f(-1, 1);
37         glEnd();
38
39         glPopAttrib();
40
41         glPopMatrix();
42         glMatrixMode(GL_MODELVIEW);
43         glPopMatrix();
44 }
45
46 void overlay_tex(struct texture *tex, float alpha)
47 {
48         overlay(tex->id, (float)tex->width / tex->height, alpha);
49 }