Jump to content
  • Advertisement
Sign in to follow this  
Solance

Texture to texture rendering or copying

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

Is there any quick way to copy or render directly to a texture? I need to be able to take portions of the image not just the whole thing 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? and please post your comments on the methods you post like what you think about them.

Share this post


Link to post
Share on other sites
Advertisement
I would use glCopyTexSubImage2D (copies a region of the framebuffer to a GL texture) and you can use it with the ARB_texture_rectangle extension if you need rectangular texture sizes, this should work quite well, the only thing when using this extension is that the texture coords would be in texel positions rather than clamped between 0 and 1.

here is how to create the texture:

// create the texture
// bind to ARB_texture_rectangle and do a glCopyTexSubImage
apiTarget = GL_TEXTURE_RECTANGLE_ARB;

glGenTextures(1, &apiName);
glBindTexture( apiTarget, apiName );

glTexParameteri( apiTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( apiTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( apiTarget, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( apiTarget, GL_TEXTURE_WRAP_T, GL_CLAMP );

glTexImage2D( apiTarget, 0, GL_RGB16, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL );








to replace a portion of a texture with a portion of the frame buffer use the
parameters provided by glCopyTexSubImage2D, just remember that in OpenGL the
2D origin is located at the BOTTOM LEFT
glEnable( apiTarget );
glBindTexture( apiTarget, apiName );
glCopyTexSubImage2D( apiTarget, 0, textureReplaceStartX, textureReplaceStartY,
startScreenX, startScreenY, width, height );
Hope this helps
Cheers
-Danu

Share this post


Link to post
Share on other sites
You'd do the texture rendering and copying before you draw your scene. ie.

1. Draw texture A to framebuffer
2. Copy portion of framebuffer to texture B
3. Clear screen / reset any other states you may have changed during steps 1 & 2
4. Draw your scene

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!