• Advertisement
Sign in to follow this  

glCopyTexImage2D

This topic is 3903 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 exactly do you copy a texture to another texture with this function? It doesn't take any textures in its parameters. I want to copy pixels from one texture to another and this seems like the function to do it. I understand all the arguments of the function, but I don't get what you do with the textures. I figure you have to have one bound, but I don't know what you do with the other. Also I wouldn't know if I should bind the one I want to copy to or from. I searched around but all I could really find was a description of what the arguments do. I figured I'd ask here since someone could probably answer this in a second. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
There is no function for doing that. glCopyTexImage2D is for copying the framebuffer to a texture which you can use for texture to texture copy if you code it right.

Share this post


Link to post
Share on other sites
If you want to copy a texture to another then you will need to use glGetTexImage() and copy that to a temp pointer and then use that pointer with glTexSubImage*()

Share this post


Link to post
Share on other sites
Ok, I'm going to use glTexSubImage2D(), but what is wrong with this code?


glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);



I know I have the pixel information in pixels. I have x set to the left part of the image I want to copy y set to the top of the image I want to copy and width and height set to the width and height. I'm not sure if you need to bind a texture because I saw an example that was using glTexSubImage2D and I didn't see a texture being bound anywhere. Can anyone help me out?

Thank you.

Share this post


Link to post
Share on other sites
You need to create a texture first the usual way except if you don't want to define the texels, put NULL for the pixels in glTexImage2D

glTexImage2D(..........., NULL);


then this will work

glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);


and use glGetError to see if errors are reported.


Share this post


Link to post
Share on other sites
I'm still confused.

I have the pixels for the entire image. Can I use those pixels and load a 4 textures each representing a quarter of the image? I would figure I could, but I just want to make sure.

Do I have to make a texture with the entire image first? I've tried doing it making a texture first and not making one and neither way works.

Right now I am creating a texture and then binding it and then calling glTexImage2D(..., NULL) making it large enough for the quarter image to fit in and putting in all the right arguments for the format and what not. Then I bind it again and call glTexSubImage2D().

So my code would look something like this:
// load texture and pixels

glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);



What am I doing wrong? It's just loading a white texture. And when I check for errors, it is not returning an error.

Share this post


Link to post
Share on other sites
white generally means there is something wrong with the filtering modes set. As I guess you aren't creating any mipmap levels try setting both the min and max filters to GL_LINEAR and see if that helps.

Share this post


Link to post
Share on other sites
You don't have to bind the created texture twice, so the second glBindTexture call is redundand. If a texture is bound it will stay this way until you bind another one.

glTexSubImage2D is used to change a part of an already existing texture to new data. If you want to create a whole new texture you can just use glTexImage2D and specify the pixel data there. Apart from that both functions work the same way.
Depending on how the pixel data is laid out in the memory area pointed to by pixels you may need to use the glPixelStore function.

Edit: And set the min and max filter as phantom pointed out.

Share this post


Link to post
Share on other sites
I figured I wouldn't need to bound them twice.

Anyways, how do I create a whole new texture from the pixel data and load it into four textures when I can only change the width and the height? I'd need to change the x and the y.

Do I need to create the texture four times and then call glTexSubImage2D() four times to get the right sub images? Or can I just call glTexImage2D() with the pixel data that I have?

Also, I am setting the min and max filters. I am just trying to make this as easy to look at as possible.

Thank you.

Share this post


Link to post
Share on other sites
I figured I wouldn't need to bound them twice.

Anyways, how do I create a whole new texture from the pixel data and load it into four textures when I can only change the width and the height? I'd need to change the x and the y.

Do I need to create the texture four times and then call glTexSubImage2D() four times to get the right sub images? Or can I just call glTexImage2D() with the pixel data that I have?

Also, I am setting the min and max filters. I am just trying to make this as easy to look at as possible.

Thank you.

edit:

I don't know how I posted this twice. -- Sorry

[Edited by - yahn on August 13, 2007 1:23:11 PM]

Share this post


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

  • Advertisement