Sign in to follow this  
Solance

Texture to texture rendering or copying

Recommended Posts

Solance    102
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
silvermace    634
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
The Rug    628
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this