Results 1 to 5 of 5

Thread: Is there a way to crop a texture?

  1. #1
    Member Newbie
    Join Date
    Jul 2013

    Is there a way to crop a texture?

    I have a video stream coming in at 1920x1080 that I want to crop to 2048x1024 with black borders so I can have mipmaps. Is there a command that will do this for me automatically?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    When you render a texture it maps to the uv texture coordinates of the triangle (or quad) you are drawing. Normally you would use 0,0 to 1,1 so that the texture completely filled the quad; but if you use 0,0,2,2 and set GL_TEXTURE_WRAP_S and GL_TEXTURE_WRAP_T to GL_CLAMP_TO_BORDER with glTexParameter then the image will be drawn in the bottom left quarter and the rest of the quad will fill with the border colour.In you case I think you want
    Code :
    dx = 2048.9/1920.0 - 1.0;
    u for left is dx/2
    u for right is 1+dx/2
    I am not sure what you want to do with the height since you images is larger than the display area. To crop
    Code :
    dy = 1.0 - 1024.0/1080.0
    v left dy/2
    v right 1 - dy/2

  3. #3
    Member Newbie
    Join Date
    Jul 2013
    No, I need to crop the texture before rendering so I can get mipmaps.

  4. #4
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    I believe most implementations these days support ARB_texture_non_power_of_two so unless you need to support one that does not have this you can get mip maps without doing anything.
    Otherwise you should be able to set the GL_UNPACK_* parameters with glPixelStore to crop the texture during upload - note this will throw away pixels, not perform any rescaling, but it sounds like that is what you want.

  5. #5
    Member Newbie
    Join Date
    Jul 2013
    I'm not sure how glPixelStore is used. Is there a tutorial on the site?

Similar Threads

  1. Copy Crop of Multisample Texture , alpha to coverage
    By Christoph.LGDV in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 03-23-2017, 08:14 AM
  2. Replies: 1
    Last Post: 12-26-2014, 04:57 PM
  3. How to crop just one shape
    By varieux in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-07-2010, 12:07 PM
  4. (pre-)crop texture
    By dronus in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 10-08-2005, 04:42 PM
  5. Replies: 2
    Last Post: 09-27-2004, 05:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean