I had this code (github.com/remap/YoutubeTOP/blo … .cpp#L1101) working some time ago, where I render arbitrary (A)RGB buffer (uint8_t*) using OpenGL and it was working fine.
Now, (using macOS as target platform) most of this code does not compile as there’s new “#include <OpenGL/gl3.h>” header, which renders many gl functions that I use as undefined.
Moreover, I initialize my TOP with info.executeMode = TOP_ExecuteMode::OpenGL_FBO;
and would like to use OpenGL FBO (I think, it’ll be faster?).
So far, that’s what I tried and it doesn’t work:
- create texture (called once):
glGenTextures(1, (GLuint*)&texture_);
glBindTexture(GL_TEXTURE_2D, texture_);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width_, height_, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- initialize framebuffer with texture (called once):
glFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
texture_,
0);
glGenRenderbuffers(1, &depthBuffer_);
glBindRenderbuffer(GL_RENDERBUFFER, depthBuffer_);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, 1024, 768);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthBuffer_);
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
glDrawBuffers(1, DrawBuffers);
- inside
execute()
, render into texture (called on every cook):
context->beginGLCommands();
glViewport(0, 0, width_, height_);
glClearColor(0.0, 1.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture_);
// TODO: convert ARGB to RGBA
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width_, height_, GL_RGBA, GL_UNSIGNED_BYTE, buffer_);
context->endGLCommands();
I don’t work with OpenGL much except when I need to render a random video on an arbitrary texture, so I’m clearly missing something crucial here. Any ideas are welcome!
Thanks