Copying a subarea of one texture to another

Started by
6 comments, last by MARS_999 18 years ago
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.
Advertisement
assuming texture is r,g,b:

float *small_tex = new float[3 * 16 * 16];    // r, g, bint start_row, start_col;                     // top-left corner of samplefor (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.
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?
sorry, that was me :)
As far as I know, there is no OpenGL function which will return a portion of a texture.
Understood, Thank you very much.
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.
Look into glCopyTexSubImage2D() HTH

This topic is closed to new replies.

Advertisement