GLSL shaders to create a zoom

Howdy coders,

I am trying to create a sniper scope as a post effect using GLSL shaders. I may be well off here but my idea was to render the image at (lets say) double screen size, capture this as a texture, then scale it back down to screen size, with the exception of pixels within a specified radius of the mouse position (these points would take the appropriate points of the larger image - therefore I would not lose detail like I would if I just stretched out a smaller image).

I think I know how to do the majority of this as far as the actual shader is concerned, my issue is how to I render the double size image to the back buffer to capture this as a texture. I know to make my personal buffer 4 times the size to keep the information, but I am unsure how to render double size in the first place.

Have been going through orange book and online tutorials, but am running short on time as this is a deadlined assignment (hence why I dont want all the answers, just pointing in right dirction)

Any help most appreciated, and first person to lead me to right answer gets an imaginary cookie :0)


I think you would be better by changing the FOV (field of view) value of the projection matrix.
Such is usually changed using the ‘gluPerspective()’.

The field of view will dictate how wide is the angle of capture of the rendered scene. Thus, by reducing this angle you will capture less scene in the same pixels, givin the sensation of zooming in.


I agree this would certainly be easier for me, however my spec says I need to use shaders to handle the zoom. Also, having re-read the spec it seems I am slightly off with how this should work.

It turns out that I am suppossed to:
Create a circular tile.
Stretch out a smaller circle to fit this tile and apply it to the circular tile as a texture (using shaders).

So my hope of not losing detail is defunct, as it is specified that I am just suppossed to be magnifying a point on an image as oppossed to performing ‘true’ zoom. It matters not that I woould lose 3d scene detail, just that I can prove that I am able to manipulate the grabbed texture from the rendered scene.

I must point out here that I am useless at graphics and my real skill lies in AI, so I apologise if this should be cake, it would appear my baking skills are sub par :0(

I am currently trying to work out how to use a shader to manipulate a quad into a circle (I believe use the vertex shader for this, but if I shrug any harder at this point my head will fall off)

Did I mention I am not very good at graphics?

Ok, some progress, decided to ignore the whole circle tile thing. Now I need to know what is wrong with this:

Am trying to work out screen position of texture co-ordinate. I know the issue is where I calculate compX and compY.

void main(void)
radComp = 2500;

tempTex = vec2(texCoord*Screen);						//finding pixel pos
tempTexCoord.x = tempTex.x/Screen;						//pixel pos, dividing it by screen to get that pixel texture co-ordinate
tempTexCoord.y =  tempTex.y/Screen;						//pixel pos, dividing it by screen to get that pixel texture co-ordinate

xComp = (tempTexCoord.x) - mouseX;

yComp = (tempTexCoord.y) - mouseY;

if(((xComp * xComp) + (yComp * yComp)) < radComp)
	tempTexCoord.x = (mousePos.x + (xComp/2))/Screen;
	tempTexCoord.y = (mousePos.y + (yComp/2))/Screen;
	grab = vec4(texture2D(grabTexture, tempTexCoord.xy));
	grab = vec4(texture2D(grabTexture, texCoord.xy));

	//just use current location

vec3	colour = vec3( * Intensity);

gl_FragColor = vec4( vec3(colour), 1.0 );
//post as this colour


I dont believe code for calculating temTexCoord is correct. The shader seems to zoom fine when tested always going in to if and renders normally when always going in to else.

Any Clues you lovely lovely people??

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.