Open GL c++ question

Started by
11 comments, last by Solance 18 years, 11 months ago
How do i add part of a texture to another texture? in opengl and c++??? like i dont want to just add the whole texture to the other one i just need to grab a certian portion of it for example: lets say we have a image 128x128 i need to just grab a part of it lets say 64x64, and add this to another texture. how would i accomplish this?
Advertisement
Are you wanting to load the textures with OGL and use OGL to place a part of one image on top of the other? Or do you want to do this on the CPU, and then load the final texture to OGL?

Slaru
ok what i am doing is i have a set of textures and each time a item is added to them by glTexImage2D();, but it adds them from there own seperate OPEN gl texture i just need to have one big texture and just take portions without having a seperate texture for each one.
anyone?
hum... i really need to figure out how to do this. its quite annoying.
If I understand you right I think you probably want a combination of GL_EXT_framebuffer_object and glCopyTexSubImage2D. Basically, bind your source texture as the read buffer and then glCopyTexSubImage2D to your destination texture.

I'm not saying there isn't an easier or more efficient way, but that's the best I could come up with at short notice.

Enigma
ok thanks.


anyother methods?
You're drifting from one thing to another, so I'll split my post up to make it a little easier to follow.

In your first post, you say you want to add a part (here-by known as SUB_1) of a texture (here-by known as TEX_1), and you want to insert that into another texture (here-by known as TEX_2), specifically, a sub-part of TEX_2 (here-by known as SUB_2).

In your second post, you say you want to add the entire image TEX_1 to some part of TEX_2 (SUB_2).

[EDIT]
- changed the 'first post' part a little, since it needed to be a little more specific -
- changed the 'second post' part to suit the changes made to the 'first post' part -
- moved diagrams up here -
[/EDIT]

OK, I'll try to do this real pretty like...
From post 1:TEX_1:+-----+|  _  || |_| | <-- the thing in the middle is SUB_1|     |+-----+TEX_2:+-----+|  _  || |_| | <-- the thing in the middle is SUB_2|     |+-----+From post 2:TEX_1: _|_|TEX_2:+-----+|  _  || |_| | <-- the thing in the middle is SUB_2|     |+-----+



Now inserting TEX_1 into SUB_2 is easy, you just need to use glTexSubImage2D.

On the other hand, if you wanted to add SUB_1 to SUB_2, you'll need to use glCopyTexSubImage2D to read the frame buffer into another texture (here-by known as TEX_3). The only easy way to do this would be to set up a orthogonal projection matrix (2D, -1,-1 to +1,+1 would do), use glRasterPos2d() (no opengl.org page on this, so you'll need to google it if you don't understand how it works), create your texture (TEX_3), with a width and height (which should be the dimensions of SUB_1, which should also be be power-of-twos if your videocard doesn't support non-power-of-two textures) then use glDrawPixels to draw all of TEX_1, bind TEX_3 to GL_TEXTURE_2D, then use glCopyTexSubImage2D to copy SUB_1 into TEX_3. From there, you use glTexSubImage2D() (seen in the method above) to copy TEX_3 into SUB_2.

I could be wrong about that being the easiest method, but then again, I changed bits and pieces of it quite a few times, so the whole thing's probably messed up quite a bit...

At any rate, that *should* get you what you required from your first post, and is obviously far more difficult than the requirements of your second post...

Enigma, the FBOs would be nice, but from what I've heard, the only support for them is in beta drivers (but then again, maybe I've been reading too many old threads again...). It'd make it far easier than doing this...

I suppose you could always use a pbuffer...

Maybe I'm complicating things too much...
any other possible methods and let me elaborate on what i am doing

i am takeing a part of a image for example

IMAGE THAT NEEDS COPYING
-------
| 1| 2 |
|__|__ |
| 3| 4 |
|__|__ |


IMAGE TO COPY TO


-------
| 1| 2 |
|__|__ |
| 3| 4 |
|__|__ |

i need to be able to take portion 4 for example and add it to portion 1 of the other texture. get it?
*cough* GameDev's OpenGL Forum *cough*
[ ThumbView: Adds thumbnail support for DDS, PCX, TGA and 16 other imagetypes for Windows XP Explorer. ] [ Chocolate peanuts: Brazilian recipe for home made chocolate covered peanuts. Pure coding pleasure. ]

This topic is closed to new replies.

Advertisement