I'm not sure how possible this is, but I'm trying to use a fragment shader to draw a portion of a texture in the middle of a quad. This is all 2D. The quads consist of four vertices from (0, 0) to (width, height). The modelview matrix is transformed to position the quads.
I have a sprite sheet of 32x32 icons and a 32x32 quad that one of the icons is mapped to. In a vertex shader, I'm creating a 2 pixel 'border' around the quad by moving it's vertices out by 2 pixels. In a fragment shader, I want to display the texture with it's original size, in it's original position; basically, there should be no visible difference between the original 32x32 quad and the 36x36 quad. The result should be an invisible 'border'.
The only solution I can come up with is calculating the window coordinate for the corner of the quad in the vertex shader, then passing it to the fragment shader and subtracting it from gl_FragCoord, in order to get the position of each pixel relative to the corner of the quad. With this information, I can display the texture in the center of the quad, with it's original size.
Is there any easier way to accomplish this?