![]() |
|
OpenGL, copy screen to texture |
Paul whoknows
Member #5,081
September 2004
![]() |
I want to create some shaking/rotating and transition effects using OpenGl and the first thing I need is to get a copy of the screen and store it into a texture. In other words, I basically want to take a screenshot and save it into a texture, once I get it I could easily draw it to the screen with some additional effects. I am using AllegroGL, and just learning OpenGL, so I don't really have idea how to do this, any help is appreciated. Thanks in advance. ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
gnolam
Member #2,030
March 2002
![]() |
I recommend framebuffer objects. You just need a small bit of easily-wrappable boilerplate code and they Just WorkTM (and fast, too). -- |
Paul whoknows
Member #5,081
September 2004
![]() |
Thanks gnolam!, but I prefer to use only basic OpenGL functions at the moment. glBindTexture(GL_TEXTURE_2D, background); glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,512,512,0);
Now, the problem is that my game screen is 800x600 but I can only use power of two sized textures ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Kitty Cat
Member #2,815
October 2002
![]() |
Note that for offscreen rendering, using an aux buffer instead of the back/front-buffer would be preferred (though FBOs would be preferred above those). Quote: Now, the problem is that my game screen is 800x600 but I can only use power of two sized textures glViewport is your friend. Though you'll still be limitted to texture sizes that are the next lower power-of-2 (unless you have GL_ARB_texture_non_power_of_two, then it can be whatever size). That's just the price you pay for using an old offscreen rendering method. -- |
Thomas Harte
Member #33
April 2000
![]() |
Quote: Now, the problem is that my game screen is 800x600 but I can only use power of two sized textures Maybe CopyTexSubImage2D to a 1024x1024 texture? With a fallback to copy to [however many smaller textures are necessary] if your card can't handle a texture that size (which would probably mean that it's a decade old)? [My site] [Tetrominoes] |
Paul whoknows
Member #5,081
September 2004
![]() |
Already solved the problem using this: /* Set viewport so it matches the size of our texture*/ glViewport(0,0,1024,1024); /* Target texture */ glBindTexture(GL_TEXTURE_2D, tex); /* Copy screen to a 1024x1024 texture */ glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0,0,1024,1024,0); /* Restore viewport (in our case to 800x600)*/ glViewport(0,0,800,600);
This is amazing! I can copy the screen and blit it with different effects more than 15 times per frame(at 60Hz) without any drop in the frame rate in my cheap FX5700LE Quote: Note that for offscreen rendering, using an aux buffer instead of the back/front-buffer would be preferred (though FBOs would be preferred above those).
Sorry if this is a stupid question but what is FBO? I mean is another library?, an add-on? is it compatible with old video cards? Quote: Maybe CopyTexSubImage2D to a 1024x1024 texture? With a fallback to copy to [however many smaller textures are necessary] if your card can't handle a texture that size (which would probably mean that it's a decade old)? My game now needs to able to create at least one 1024x1024 texture, that means that it will not run in old graphics cards. It is really important to me to know which video cards doesn't support this texture size, is there a list or something where I can find this information? ____ "The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner. |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: what is FBO? Framebuffer Objects. It allows you to render to a user-specified renderbuffer, or directly to a texture. Quote: It is really important to me to know which video cards doesn't support this texture size
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); -- |
Thomas Harte
Member #33
April 2000
![]() |
Quote:
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); According to the docs, it'll only give "a rough estimate of the largest texture that the GL can handle". Quote: My game now needs to able to create at least one 1024x1024 texture, that means that it will not run in old graphics cards. It is really important to me to know which video cards doesn't support this texture size, is there a list or something where I can find this information? I've seen at least one, but for the life of me I can't find it now. This olde GameDev thread reveals the following pertinent facts though:
So I really think you're going to be okay. [My site] [Tetrominoes] |
Arthur Kalliokoski
Second in Command
February 2005
![]() |
Bob said:
Quote: from They all watch too much MSNBC... they get ideas. |
|