I am very new in OpenGL but i develop software in C,C++ for over 25 years now. I am a specialist in developing digital video and photo software. Until now i only developed software with 2D graphics, but i want to go a step further and make 3D graphics which should be combined with video and photos.
For this i need a good 3D lib which let me render 3D worlds in a frame buffer, because i have to work with the result of the renderer for example to create a new video from it.
So first i need to now is:
Can I render images with OpenGL without opening a display window ? Just setup a 3D Model and let it render into a buffer and save this buffer as an image?
I know that there is something like FBO in OpenGL, but all i read about it was only to create textures which are used in the online window rendering. That’s not what I’m looking for.
Can I render images with OpenGL without opening a display window ?
In general, no. You must at least create a window.
Whether you use the window is up to you. You don’t have to render to it, after all. You can create the window, minimize it, and then just render to a Framebuffer Object.
I know that there is something like FBO in OpenGL, but all i read about it was only to create textures which are used in the online window rendering. That’s not what I’m looking for.
Those examples all show you everything you need to know. They show you how to set up an FBO as a render target. They show you how to attach images to the target. They show you how to render to it.
Yes, they also show you how to use that rendered texture in a different scene to render to the default framebuffer. But just don’t do that part. You don’t have to copy-and-paste all of the example code into your project.
This reads an area of pixels from the currently bound read buffer and puts it into a memory segment pointed to by data.
You can switch the read buffer with glReadBuffer(GL_COLOR_ATACHMENTi). Also note that if you don’t bind the FBO as a GL_READ_FRAMEBUFFER then you’ll copy pixels from the default framebuffer. So the algorithm is:
a) Render to FBO
b) Set the color attachment you want to read from (if you’ve got only one attachment at COLOR_ATTACHMENT0 you don’t need to call glReadBuffer() since it defaults to that value)
c) Bind the FBO as either GL_FRAMEBUFFER or GL_READ_FRAMEBUFFER (notice, GL_DRAW_FRAMEBUFFER and GL_READ_FRAMEBUFFER are explicit bindings while GL_FRAMEBUFFER binds the FBO as both)
d) ReadPixels from the FBO
Edit: Also make sure that you allocate enough data in client memory for the GL to write to. For instance, reading 4 RGBA pixels of GL_FLOAT means you’ll have to allocate at least 4 * 4 * sizeof(GLfloat) in data (4 pixels, 4 components each, 4 bytes each).
Thallius, I forgot to mention that readback operations such as glReadPixels are costly and should not be taken lightly when striving for high performance.
AFAIK, Windows is the only platform that requires you to make an actual ‘window’. Mac and iOS just needs a context, Linux and derivatives can use pbuffers (including Android, apparently).
So in general, no, you don’t need an actual window.