forked from goliath/shadermeh
Keep global state clean
Unbind the FBO+texture after initialization, bind it before rendering, unbind it after, re-bind the texture to scrape the data, unbind the texture. Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
parent
6bfa914582
commit
22b2fd4864
1 changed files with 12 additions and 0 deletions
12
shadermeh.c
12
shadermeh.c
|
@ -232,10 +232,13 @@ int main(int argc, char **argv)
|
|||
glBindTexture(GL_TEXTURE_2D, fbo_tex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
|
||||
fbo_tex, 0);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
} else {
|
||||
window_show(wnd);
|
||||
}
|
||||
|
@ -244,6 +247,10 @@ int main(int argc, char **argv)
|
|||
while (to_stdout || window_handle_events()) {
|
||||
/* render image to FBO */
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_start);
|
||||
|
||||
if (to_stdout)
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
|
@ -255,9 +262,14 @@ int main(int argc, char **argv)
|
|||
|
||||
/* get image from FBO, dump to stdout */
|
||||
if (to_stdout) {
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo_tex);
|
||||
|
||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, fb32);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
convert_for_ffmpeg(fb32, fb24, width, height);
|
||||
|
||||
if (write_retry(STDOUT_FILENO, fb24,
|
||||
|
|
Loading…
Reference in a new issue