10 #include <OpenGL/CGLMacro.h>
18 "title" :
"VuoImageResize",
30 \n#include
"VuoGlslAlpha.glsl"
32 varying vec2 fragmentTextureCoordinate;
33 uniform sampler2D texture;
37 bool outOfBounds(vec2 coord)
39 return coord.x < 0 || coord.x > 1 || coord.y < 0 || coord.y > 1;
44 vec2 uv = (fragmentTextureCoordinate - offset) * scale;
45 gl_FragColor = outOfBounds(uv) ? vec4(0.,0.,0.,0.) : VuoGlsl_sample(texture, uv);
53 \n#include
"VuoGlslAlpha.glsl"
55 varying vec2 fragmentTextureCoordinate;
56 uniform sampler2DRect texture;
59 uniform vec2 textureSize;
61 bool outOfBounds(vec2 coord)
63 return coord.x < 0 || coord.x > 1 || coord.y < 0 || coord.y > 1;
68 vec2 uv = (fragmentTextureCoordinate - offset) * scale;
69 gl_FragColor = outOfBounds(uv) ? vec4(0.,0.,0.,0.) : VuoGlsl_sampleRect(texture, uv * textureSize);
120 if (sizingMode == VuoSizingMode_Proportional)
128 targetHeight *= (float)width / image->
pixelsWide;
130 if (targetHeight > height)
132 targetWidth *= (float)height / targetHeight;
133 targetHeight = height;
137 height = targetHeight;
141 float v = height / (float)(image->
pixelsHigh);
143 VuoPoint2d scale = (VuoPoint2d) { 1, 1 };
144 VuoPoint2d offset = (VuoPoint2d) { 0, 0 };
148 case VuoSizingMode_Fit:
149 if( u < v && u * image->pixelsHigh < height)
151 scale = (VuoPoint2d) { 1, height/(image->
pixelsHigh*u) };
152 offset = (VuoPoint2d) { 0, ((height-(image->
pixelsHigh*u))/2)/height };
156 scale = (VuoPoint2d) { width/(image->
pixelsWide*v), 1 };
157 offset = (VuoPoint2d) { ((width-(image->
pixelsWide*v))/2)/width, 0 };
161 case VuoSizingMode_Fill:
164 scale = (VuoPoint2d) { 1, height/(image->
pixelsHigh*u) };
165 offset = (VuoPoint2d) { 0, ((height-(image->
pixelsHigh*u))/2)/height };
169 scale = (VuoPoint2d) { width/(image->
pixelsWide*v), 1 };
170 offset = (VuoPoint2d) { ((width-(image->
pixelsWide*v))/2)/width, 0 };
181 shader = resize->shader;
184 shader = resize->shaderRect;