Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » OpenGL, copy screen to texture

This thread is locked; no one can reply to it. rss feed Print
OpenGL, copy screen to texture
Paul whoknows
Member #5,081
September 2004
avatar

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
avatar

I recommend framebuffer objects. You just need a small bit of easily-wrappable boilerplate code and they Just WorkTM (and fast, too).
Short tutorial: http://www.gamedev.net/reference/articles/article2331.asp

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Paul whoknows
Member #5,081
September 2004
avatar

Thanks gnolam!, but I prefer to use only basic OpenGL functions at the moment.
Well, searching in the forum I've found this is an easy way to do it:

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 :P

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Kitty Cat
Member #2,815
October 2002
avatar

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.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Thomas Harte
Member #33
April 2000
avatar

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)?

Paul whoknows
Member #5,081
September 2004
avatar

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 :o

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
avatar

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);
Will give the maximum texture size the card can support.

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Thomas Harte
Member #33
April 2000
avatar

Quote:

glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size);
Will give the maximum texture size the card can support.

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:

  • The NVidia Riva TNT 2 has a maximum texture size of 2048×2048

  • The ATI Rage Fury Pro has a maximum texture size of 1024×1024

  • The Matrox Millennium G200 has a maximum texture size of 2048×2048

  • The Voodoo5 5500 has a maximum texture size of 2048×2048

So I really think you're going to be okay.

Arthur Kalliokoski
Second in Command
February 2005
avatar

Bob said:

Quote:
Can [the usual video card of today] do 1024 x 1024 textures?
Every GPU ever built, except the Voodoo 1 to 3.

from

http://www.allegro.cc/forums/thread/524349

They all watch too much MSNBC... they get ideas.

Go to: