Make the window invisible if dumping to stdout

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2022-07-17 02:33:15 +02:00
parent 319b283868
commit f21ecc71c7
3 changed files with 51 additions and 28 deletions

View File

@ -223,26 +223,41 @@ 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);
} else {
window_show(wnd);
}
/******************** drawing loop ********************/
while (window_handle_events()) {
while (to_stdout || window_handle_events()) {
/* render image to FBO */
if (to_stdout)
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_start);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
if (!to_stdout)
if (to_stdout) {
glFlush();
} else {
window_swap_buffers(wnd);
}
/* get image from FBO, dump to stdout */
if (to_stdout) {
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA,
GL_UNSIGNED_BYTE, fb32);
convert_for_ffmpeg(fb32, fb24, width, height);
if (write_retry(STDOUT_FILENO, fb24,
width * height * 3)) {
break;
}
}
/* update timers */
clock_gettime(CLOCK_MONOTONIC_RAW, &frame_end);
iFrame += 1;
@ -252,23 +267,6 @@ int main(int argc, char **argv)
glUniform1f(u_iTimeDelta, iTimeDelta);
glUniform1f(u_iTime, iTime);
glUniform1ui(u_iFrame, iFrame);
if (to_stdout) {
/* get image from FBO */
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 to 24 bps and dump to stdout */
convert_for_ffmpeg(fb32, fb24, width, height);
if (write_retry(STDOUT_FILENO, fb24,
width * height * 3)) {
break;
}
}
}
/******************** cleanup ********************/

View File

@ -36,6 +36,10 @@ void window_set_vsync(window *wnd, int enable);
void window_destroy(window *wnd);
void window_show(window *wnd);
void window_hide(window *wnd);
bool window_handle_events(void);

View File

@ -194,12 +194,9 @@ window *window_create(unsigned int width, unsigned int height,
XSaveContext(x11_globals.dpy, this->wnd,
x11_globals.xctx, (XPointer)this);
/* set the caption and make the window visible */
/* set the caption */
XStoreName(x11_globals.dpy, this->wnd, caption);
XMapWindow(x11_globals.dpy, this->wnd);
this->visible = true;
x11_globals.vis_wnd_count += 1;
this->visible = false;
/* flush any pending requests to the X Server */
XFlush(x11_globals.dpy);
@ -251,6 +248,30 @@ void window_destroy(window *this)
free(this);
}
void window_show(window *this)
{
if (this->visible)
return;
XMapWindow(x11_globals.dpy, this->wnd);
XFlush(x11_globals.dpy);
this->visible = true;
x11_globals.vis_wnd_count += 1;
}
void window_hide(window *this)
{
if (!this->visible)
return;
XUnmapWindow(x11_globals.dpy, this->wnd);
XFlush(x11_globals.dpy);
this->visible = false;
x11_globals.vis_wnd_count -= 1;
}
bool window_handle_events(void)
{
window *wnd;