TpoM6oH
TpoM6oH

Reputation: 8585

Scale and paint over with OpenGL ES shader on android

I need to make something like motion effect on an image. For this I need to scale the original image and paint it over the not scaled original image with some transparency.

How to do it in an opengl shader?

Upvotes: 1

Views: 312

Answers (1)

Matic Oblak
Matic Oblak

Reputation: 16774

You don't need a specific shader for that, you can just draw 2 texture rects where second is scaled. To ensure the blending between the 2 images use "glColor4f" or something similar between the 2 draw calls (before the second draw call set color4f(1,1,1,.5f)) but don't forget to set it back to (1,1,1,1) after the draw.

If you really need to do this in one call in a shader: Take a most common shader for drawing a textured shape, add some "scale" parameter as input. Then

vec2 scaledCoordinate = vec2((texCoord.x-.5)/scale + .5, (texCoord.y-.5)/scale + .5)

then use something like this:

gl_FragColor = mix(texture2D(texture, texCoord), texture2D(texture, scaledCoordinate), .5);

Upvotes: 1

Related Questions