We are able to use the mpv library to draw onto the bottom-left corner of an OpenGL window. While mpv seems able to draw an arbitrary width and height, the only way we found to draw to another location is to write to another frame buffer, but then we have to blit the second frame buffer onto the first.
Is there a way to tell mpv to draw into OpenGL onto (x,y,w,h)?
Also, when we copy it crashes multiple times, then suddenly starts wortking which is very odd. Even when it works, it shows two pictures which we completely don't understand.
To create the frame buffer:
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, drawWidth, drawHeight, 0, GL_RGB,
GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
texture, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
To copy the movie framebuffer into the regular one:
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
std::cout << "ERROR::FRAMEBUFFER:: Framebuffer is not complete!"
<< std::endl;
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
checkError(mpv_render_context_render(mpv_gl, redrawParams));
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_BUFFER, fbo);
glBlitFramebuffer(0, 0, drawWidth, drawHeight, x, y, x + drawWidth,
y + drawHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);