Jump to content
  • Advertisement
Sign in to follow this  
Solance

Open GL c++ question

This topic is 4799 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

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!