Skip to main content
GameDev.net gamedev.net
🔒 Locked

Offscreen rendering

Started by daviddoria Feb 25, 2009 at 5:23 PM 9 replies 2.3k views
Original Post
daviddoria
daviddoria
I would like to get the contents of the color buffer and depth buffer that would have been displayed but without displaying them. I read that you can use frame buffer objects (FBOs) but all of the FBO examples I saw were talking about textures and all kinds of stuff that I don't need. I just want to save an image of a very basic model from different viewpoints without displaying it on the screen. Does anyone have an example of that / any examples? Thanks, Dave
daviddoria
daviddoria
Can you render the depth buffer to a texture as well?
dpadam450
dpadam450
You can do whatever. If your app doesn't eat alot of graphics power, then:

Draw scene, glCopyTexImage2D.
Clear out the screen/depth.
Draw what you actually want on the screen.

If your app does eat a lot:

Make a fbo (1 or 4) and just use those. Its not complicated.
NBA2K, Madden, Maneater, Killing Floor, Sims 
BionicBytes
BionicBytes
You don't even need to use an FBO. Standard GL functionality should be more than sufficient, unless you're drawing zillions of polygons and performance really matters.

daviddoria
daviddoria
BionicBytes, you're saying I don't need to make a window at all? Just do this

int main(int argc, char *argv[]){	display();	return 0;}void display(void){	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glEnable(GL_DEPTH_TEST);	LookAt();	DrawCube();	ReadDepthBuffer();	WriteRGBImage();}


I tried that and the depth buffer and the color buffer are just all black. Maybe I misunderstood?
Fiddler
Fiddler
No, that won't work. To use OpenGL you need an OpenGL context.

Solution: create an invisible window.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
daviddoria
daviddoria
You are right, I needed a context!

I also had to add

glDrawBuffer(GL_NONE);

and then the COMPLETE test passed.

So now I need to get the values of the depth buffer - I was trying:

glReadBuffer(GL_FRAMEBUFFER_EXT);glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, depths);


but they are all just black. How should I get the values into an array?

Thanks,
Dave
Fiddler
Fiddler
I'm pretty sure you don't even need to use FBOs in this case: just render to the normal backbuffer, call SwapBuffers and use glReadPixels or glGetTexSubImage2D to read back the data from the front buffer.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]
daviddoria
daviddoria
but the idea is to do it without a window.. so how would you do that? creating the context makes the window (at least with glut), right?
Fiddler
Fiddler
I don't know about GLUT specifically, but you should be able to create an invisible window, or perhaps hide the window after you create it. The specifics depend on the toolkit you use, but I've used this method successfully in the past with C# & Windows.Forms.
[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.