textures, overlay images, libimago
[demo_prior] / src / post.c
diff --git a/src/post.c b/src/post.c
new file mode 100644 (file)
index 0000000..c1a2a23
--- /dev/null
@@ -0,0 +1,49 @@
+#include "opengl.h"
+#include "texture.h"
+#include "post.h"
+#include "demo.h"
+
+void overlay(unsigned int tex, float aspect, float alpha)
+{
+       float xscale = aspect / win_aspect;
+
+       glMatrixMode(GL_MODELVIEW);
+       glPushMatrix();
+       glLoadIdentity();
+       glMatrixMode(GL_PROJECTION);
+       glPushMatrix();
+       glLoadIdentity();
+       glScalef(xscale, 1.0, 1.0);
+
+       glPushAttrib(GL_ENABLE_BIT);
+       glDisable(GL_DEPTH_TEST);
+       glDisable(GL_LIGHTING);
+       glEnable(GL_BLEND);
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glEnable(GL_TEXTURE_2D);
+
+       glBindTexture(GL_TEXTURE_2D, tex);
+
+       glBegin(GL_QUADS);
+       glColor4f(1, 1, 1, alpha);
+       glTexCoord2f(0, 1);
+       glVertex2f(-1, -1);
+       glTexCoord2f(1, 1);
+       glVertex2f(1, -1);
+       glTexCoord2f(1, 0);
+       glVertex2f(1, 1);
+       glTexCoord2f(0, 0);
+       glVertex2f(-1, 1);
+       glEnd();
+
+       glPopAttrib();
+
+       glPopMatrix();
+       glMatrixMode(GL_MODELVIEW);
+       glPopMatrix();
+}
+
+void overlay_tex(struct texture *tex, float alpha)
+{
+       overlay(tex->id, (float)tex->width / tex->height, alpha);
+}