8 static unsigned int fbtex_gltexid[2];
9 static unsigned int fbo[2], rbuf_depth[2];
10 struct texture fbtex[2];
17 glGenTextures(2, fbtex_gltexid);
18 glGenRenderbuffers(2, rbuf_depth);
21 fbtex[i].id = fbtex_gltexid[i];
26 glBindTexture(GL_TEXTURE_2D, fbtex[i].id);
27 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
28 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
33 void post_cleanup(void)
35 if(fbtex_gltexid[0]) {
36 glDeleteTextures(2, fbtex_gltexid);
39 glDeleteRenderbuffers(2, rbuf_depth);
42 glDeleteFramebuffers(2, fbo);
46 void post_reshape(int x, int y)
50 if(x != fbtex[0].width || y != fbtex[0].height) {
51 ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA;
54 glBindTexture(GL_TEXTURE_2D, fbtex[i].id);
55 glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
59 glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]);
60 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y);
64 glGenFramebuffers(2, fbo);
66 glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]);
67 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbtex_gltexid[i], 0);
68 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]);
70 glBindFramebuffer(GL_FRAMEBUFFER, 0);
75 void overlay(unsigned int tex, float aspect, float alpha)
77 float xscale = aspect / win_aspect;
79 glMatrixMode(GL_MODELVIEW);
82 glMatrixMode(GL_PROJECTION);
85 glScalef(xscale, 1.0, 1.0);
87 glPushAttrib(GL_ENABLE_BIT);
88 glDisable(GL_DEPTH_TEST);
89 glDisable(GL_LIGHTING);
91 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
92 glEnable(GL_TEXTURE_2D);
94 glBindTexture(GL_TEXTURE_2D, tex);
97 glColor4f(1, 1, 1, alpha);
111 glMatrixMode(GL_MODELVIEW);
115 void overlay_tex(struct texture *tex, float alpha)
117 overlay(tex->id, (float)tex->width / tex->height, alpha);