8 static unsigned int post_fbtex_gltexid[2];
9 static unsigned int rbuf_depth[2];
11 unsigned int post_fbo[2];
12 struct texture post_fbtex[2];
15 unsigned int post_sdr[MAX_POST_SDR];
20 static const char *psdr_fname[] = {"sdr/oldfig.p.glsl"};
22 for(i=0; i<MAX_POST_SDR; i++) {
23 if(!(post_sdr[i] = create_program_load("sdr/post.v.glsl", psdr_fname[i]))) {
28 glGenTextures(2, post_fbtex_gltexid);
29 glGenRenderbuffers(2, rbuf_depth);
32 post_fbtex[i].id = post_fbtex_gltexid[i];
33 post_fbtex[i].width = 0;
34 post_fbtex[i].height = 0;
35 post_fbtex[i].pixels = 0;
37 glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
44 void post_cleanup(void)
46 if(post_fbtex_gltexid[0]) {
47 glDeleteTextures(2, post_fbtex_gltexid);
50 glDeleteRenderbuffers(2, rbuf_depth);
53 glDeleteFramebuffers(2, post_fbo);
57 void post_reshape(int x, int y)
61 if(x != post_fbtex[0].width || y != post_fbtex[0].height) {
62 ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA;
65 glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
66 glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
67 post_fbtex[i].width = x;
68 post_fbtex[i].height = y;
70 glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]);
71 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y);
75 glGenFramebuffers(2, post_fbo);
77 glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[i]);
78 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, post_fbtex_gltexid[i], 0);
79 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]);
81 glBindFramebuffer(GL_FRAMEBUFFER, 0);
86 void overlay(unsigned int tex, float aspect, float alpha)
88 float xscale = aspect / win_aspect;
90 glMatrixMode(GL_MODELVIEW);
93 glMatrixMode(GL_PROJECTION);
96 glScalef(xscale, 1.0, 1.0);
98 glPushAttrib(GL_ENABLE_BIT);
99 glDisable(GL_DEPTH_TEST);
100 glDisable(GL_LIGHTING);
102 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
103 glEnable(GL_TEXTURE_2D);
105 glBindTexture(GL_TEXTURE_2D, tex);
108 glColor4f(1, 1, 1, alpha);
122 glMatrixMode(GL_MODELVIEW);
126 void overlay_tex(struct texture *tex, float alpha)
128 overlay(tex->id, (float)tex->width / tex->height, alpha);