Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 9 of 9

Thread: copying texture to an array

  1. #1
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    copying texture to an array

    Hi,

    I want to copy a previously assigned texture image to an array so that I can dynamically modify and update the texture.Thanks in advance.

    Regards,
    brett.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: copying texture to an array

    This is not a good practice, it is better to copy directly the image data to the array before creating a texture with it. Then use glTexSubImage2D to update part of (or the whole) existing texture.

    But if you really want to do copy back data from texture to an array, you can :
    http://www.opengl.org/sdk/docs/man/x...etTexImage.xml

  3. #3
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: copying texture to an array

    Hi Thank you zbuffer for the reply.I can use gltexsubImage2D but does it work for any rectangle,i.e for a rectangle that I want to fill may be a rotated rectangle w.r.t texture.Since I can supply only the offset , height and width for glTexsubImage2d() How can I use gltexsubimage2d for such a rectangle??All I have is four texture coordinates of that rectangle.

  4. #4
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: copying texture to an array

    You can't.

    You can only work with textures which are defined as per glTexSubImage2D, and then use geometry and texture coords to place that texture on the screen rotated or otherwise... or use texcoords to pull non-square shapes out of the texture for use on screen. You cannot write them to textures rotated.

    If you really must draw to an image rotated into another texture then you are going to need to create an FBO with a texture. Then get the image you want to place in that texture into another texture (or define it as pure geometry - perhaps a point array generated from a jpg or png) and use the OpenGL pipeline to draw it into the FBO the same way you would with geometry and textures to the screen.. But that's really only useful for procedural texture generation on mobile hardware where texture uploading is too slow otherwise..

    I think you will be able to find a much simpler way by rethinking your overall problem...

  5. #5
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: copying texture to an array

    Is there a simpler approach.I cannot rotate the texture all I have is 4 points of rectangle inside a texture.It can be in any orientation!

  6. #6
    Advanced Member Frequent Contributor scratt's Avatar
    Join Date
    May 2008
    Location
    Thailand
    Posts
    556

    Re: copying texture to an array

    It's not clear what you are saying.. I suspect that you have some misconceptions about OpenGL.

    If you want to draw a texture on the screen rotated then you use a QUAD and texture coordinates, and a texture as your source for the image you are putting on that QUAD. It's that simple.

    If you want to draw at an angle *into* a texture then the method I outline above is about the only way. And that's what you seemed to be asking for. Although I have not idea why you'd want to do that.

    Can I make a suggestion? Go read The Red Book cover to cover. It'll take you about half a day and will save you a lot of time..

  7. #7
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: copying texture to an array

    Can you give more detail about rendering to a FBO technique please.

  8. #8
    Intern Contributor
    Join Date
    Sep 2008
    Posts
    65

    Re: copying texture to an array

    ok I got it.rendering to the fbo is all I have to do.

  9. #9
    Junior Member Regular Contributor Heiko's Avatar
    Join Date
    Aug 2008
    Location
    the Netherlands
    Posts
    170

    Re: copying texture to an array

    Quote Originally Posted by brett01
    Hi Thank you zbuffer for the reply.I can use gltexsubImage2D but does it work for any rectangle,i.e for a rectangle that I want to fill may be a rotated rectangle w.r.t texture.Since I can supply only the offset , height and width for glTexsubImage2d() How can I use gltexsubimage2d for such a rectangle??All I have is four texture coordinates of that rectangle.
    You could use gltexsubImage2D, but you'll need some tricks. If the rectangle you need to update is rotated, you could update a slightly larger rectangle in the texture that is not rotated but includes the entire rotated rectangle. This is not hard, say for example the coordinates of the rotated rectangle are:

    (0,1)
    (1,2)
    (2,1)
    (1,0)

    (in other words: it is rotated 45 degrees)

    Use gltexsubImage2D to get a slightly larger non-rotated rectangle that includes the complete rectangle. All you need is minimum and maximum x and y coordinates:

    (min_x, max_y) -> (0, 2)
    (max_x, max_y) -> (2, 2)
    (max_x, min_y) -> (2, 0)
    (min_x, min_y) -> (0, 0)

    This rectangle includes the complete rotated rectangle. Now you have the array with pixels and you have to calculate on the cpu which pixels you have to change.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •