Jump to content
  • Advertisement
Sign in to follow this  
Welford

Copying a subarea of one texture to another

This topic is 4433 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am trying to copy one area, 16x16 texels, of a bitmap, which is say 256x256 ,to a smaller one that it the same size as the sample area. Is there a function to do this? I there is one function to return a whole area of a texture from memory (the name escapes me) but what about a sub area, can it be done? or will i have to do it from main memory myself? thank for any help or advice, Welford.

Share this post


Link to post
Share on other sites
Advertisement
assuming texture is r,g,b:


float *small_tex = new float[3 * 16 * 16]; // r, g, b

int start_row, start_col; // top-left corner of sample

for (int row = 0; row < 16; row++)
{
for (int col = 0; i < 16; col++)
{
small_tex[3*(row*16+col)] = big_tex[3*((start_row+row)*256 + (start_col+col))]; // r
small_tex[3*(row*16+col)+1] = big_tex[3*((start_row+row)*256 + (start_col+col))+1]; // g
small_tex[3*(row*16+col)+2] = big_tex[3*((start_row+row)*256 + (start_col+col))+2]; // b
}
}




not tested, but this should give you an idea.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks,

So i take it i will have to do it manually? there is no variation on glGetTexture2d(sp?) that lets you specify a starting point, width and height?

Share this post


Link to post
Share on other sites
You can use a framebuffer object... here's the basics of what you would do...

- create a texture
- set your view port to be the size of the texture (in your case 16x16)
- bind the framebuffer
- set the framebuffers target to be your 16x16 texture
- bind the larger texture (the one you are copying out of)
- draw the sub area using a GL_QUAD_STRIP or something such that it takes up the entire 16x16 area (with no scaling or anything)
- disable the framebuffer object

After you do all that, you'll have a 16x16 texture with the area that you drew. The only downside to this is that the FBO (framebuffer object) requres some of the latest drivers and won't work on everyones computer.

That's the problem I'm having, and I just started a thread on rendering to a texture. You might want to keep an eye on it as it might help you out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!