PDA

View Full Version : Offscreen surfaces and texture mapping?



nullsmind
05-23-2009, 09:06 AM
Hi,

In DirectDraw/Direct3D I used offscreen surfaces for sprites. I would load the image onto the surface which was in hardware memory. I would then say I want to copy a portion (0,0) to (64,64) to the back surface. I could also choose (50,50) to (200, 200), etc. This worked well for sprite maps as there are several images usually in one loaded image. Are there offscreen surfaces or something similar, and what OpenGL version? I'm aiming for OpenGL 1.1-1.5 for this 2d project.

So, assuming this is my only way, how would I use GL_QUADS to take a portion of an image such as (50,50) to (200,100) for example and texture map that to a quad? The only examples I see on the internet are texture mapping an entire image to a quad, but this will be rare in my project. Any suggestions would be great. Thanks.

ZbuffeR
05-23-2009, 10:42 AM
You can do that with texture coordinates. Mapping an entire image involves texturing from 0 to 1 in both s and t directions.
Say you have a 256*256 texture.
To display only the (50,50) to (200,100) region, use fractinal texcoords, like these :

s0=50/256.0
t0=50/256.0
s1=200/256.0
t1=100/256.0

Use GL_NEAREST filtering, if you want to keep the rendered pixels as close as possible as original texels.

nullsmind
05-23-2009, 11:05 AM
That looks too easy :) Thanks. Are images loaded into video memory like offscreen surfaces in video memory? For example, the way this tutorial does it:

http://gpwiki.org/index.php/OpenGL:Tutorials:Tutorial_Framework:Ortho_and_Alph a

nullsmind
05-23-2009, 12:55 PM
Well, what I mean is can I determine what textures are saved in video or cpu memory?