Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a first-person shooter/strategy game using the Lightweight Java Game Library, which has support for OpenGL. I would like to create a sniper which I need to magnify the screen and project an image onto the back of the scope. I have tried using gluPerspective() for zooming in and out, but it just makes the screen go black. I am thinking about using glReadPixels for grabbing pixel data from the zoomed in image, but I'm not sure what to put in field 'data'. explanation of glreadpixels here I'm also not sure how to get the data from glReadPixels and put it back onto the back of the scope.

EDIT: I'm not doing full screen zooming, I'm showing the image on the back of the scope.

Anyone know how to do this?

share|improve this question
Is the zoomed image full screen? Or is it shown on the back of the scope like in Borderlands 2? – Byte56 Jan 24 '13 at 1:06
It is shown on the back of the scope. – acer Jan 28 '13 at 22:56
up vote 3 down vote accepted

There is a great tutorial (c++) on how to create a camera for opengl on:

It has functionality for zooming in and out. I've used it for my implementation in LWJGL.

share|improve this answer
I assumed you meant fullscreen zooming. – moby Jan 24 '13 at 1:31
The data field should be a ByteBuffer pixel = ByteBuffer.allocateDirect(3 * number of pixels); But glReadPixels is a quite heavy instruction. – moby Jan 24 '13 at 1:32
"This demo requires OpenGL 1.3 or higher support." - that isn't really welcoming, considering we're at 4.3 now – Bartek Banachewicz Jan 25 '13 at 9:02

If you want to render the scope full-screen, just change the projection accordingly, and add the crosshair onto the picture.

If you want to render the world in the scope when the gun is being held down, you have to do the same, but render to texture this time, and then project this texture on the gun's scope.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.