Results 1 to 5 of 5

Thread: GL texture rect copy?

  1. #1

    GL texture rect copy?

    Hi, I'm trying to sort of simulate SDL "style" of 2D operations via openGL and don't understand one thing.

    I need to draw a rectangular area from one texture to the screen or to another texture.

    I've found the glCopyTexImage2D() and glCopyTexSubImage2D() functions but I don't understand one thing. What is the source? I mean, do I have to first draw the source texture somewhere before I can "copy" it ?
    Feel the power of Open Source.
    <br />Feel the power of Free Pascal.

  2. #2

    GL texture rect copy?

    The glCopyTexSubImage2D() function should copy what's on the screen/framebuffer straight into the currently bound (blank) texture.

    This is an excerpt from a dynamic texture class at www.Delphi3d.net:

    [pascal]
    procedure TFrameBufferTexture.BeginTextureUpdate;
    begin
    //Save the drawing style and all settings
    glPushAttrib(GL_ALL_ATTRIB_BITS);
    glCallList(FSetup); //Setup all the drawing styles needed for the texture update
    glViewport(0, 0, FWidth, FHeight); //restrict the drawing area to the size of the texture.

    end;

    //After calling BeginTextureUpdate, you would draw onto the screen like you would normally, except it will be drawn to the texture, not the screen.

    procedure TFrameBufferTexture.EndTextureUpdate;
    begin

    // The texture is rendered, now copy the image.
    glBindTexture(GL_TEXTURE_2D, FTexture);

    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, FWidth, FHeight);

    glPopAttrib; //Restore the saved states.

    end;
    [/pascal]
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  3. #3

    GL texture rect copy?

    If you want to load a bitmap into a texture and display that on the screen, well, that's substantially easier. There are plenty of good opengl tuts out there which show "drawing your first texture"

    To get a subsection of a texture to draw, you need to alter the texture coordinates of each vertex of the rectangle drawn to the screen.

    To draw from one texture to another, you will first have to draw the first texture to the screen, then use the method described above to copy from the screen (or should I say framebuffer) to the second texture.
    My site: DelphiTuts.com (coming soon)...

    Download Font Studio 4.21 here.

  4. #4

    GL texture rect copy?

    Yes thanks, I fiddled with it yesterday and got some first results, albeit odd regarding the width and height (but I didn't change viewport so I guess that's it). I'll report the results when it's done
    Feel the power of Open Source.
    <br />Feel the power of Free Pascal.

  5. #5

    GL texture rect copy?

    Ok I got something to work but I got 2 problems:

    glCopyTexSubImage2d() doesn't work for me (result = empty texture), whereas with glCopyTexImage2d() I get the expected result BUT:

    only if I "copy" the whole thing. If I change the width or height param it get's distorted. Moving x, y works ok as long as w and h are sized as the original.

    Am I missing something here?
    Feel the power of Open Source.
    <br />Feel the power of Free Pascal.

Bookmarks

Posting Permissions

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