View bitmaps

Hi!

I am new to OpenGL. What I want to do is pretty simple. I have a large bitmap which will be displayed on an OpenGL window and the user will be able to zoom in out, and pan the bitmap freely. What is the best way to do this? Can you give me simple code examples? It is important that I do this with OpenGL.

Thank you,
Tolga Akyay

Hi !

You will find lots of tutorials if you browse around a little on this website, a quick search on google will also help you out.

When you have loaded your image into ram you could put it as a texture on a quad and then it is pretty easy to get panning and zooming going.

Texture tutorials

Mikael

Hi,

Thanks for the tip. I succeeded in loading the image on a quad as texture, but I am complete new to OpenGL concepts. Can you please provide some samples for panning and zooming?

Thank you.

Hi !

If you just want to pan and zoom the quad and does not have anything else you can just move the quad in X/Y direction to pan/tilt and move it along the Z axis to zoom in and out (use glTranslate).

Another way is to keep the quad fixed and use gluLookAt to move the “camera” to get the same effect, this works of course if you have more objects visible also, but to make real zooming you should change the field of view (fov) parameter that you pass to gluPerspective, a higher value zoom out and a smaller value zoom in.

You will find tutorials about transformations in the same place as you found the texture tutorials.

Mikael

put glTranslate (x,y) and glScale rigth before drawing the quad.
For more details on this, search for “opengl transformation and matrices” tutorials.
As well on the official GL FAQ :
http://www.opengl.org/resources/faq/technical/
http://www.opengl.org/resources/faq/technical/gettingstarted.htm#0050

Can you please post some example code or direct to some samples on the web? NeHe’s site does not have any example on what I am trying to do.

Also can I do this using glDrawPixels? Because it is faster.

Thank you.

You can also draw the pixels to the screen using glDrawPixels(), but it’s alotta slower than using textures(atleast, that’s what they told me)
And there’s another way to zoom in and out:
(searching my red-book what it was again)…
glPixelZoom(…);

Hi again!

I know you are fed up with me :slight_smile: I am close to what I achieve my goal. It takes time to get familiar to OpenGL concepts.

I am now able to pan by moving the camera on the x, y axes using glTranslate. However, I cannot move on the z axis. No matter how much I move by glTranslatef(0.0f, 0.0f, z), the output is always the same. Do I have to use some other functions? Can you give me some tips on zooming.

Thanks.

Zooming with gltranslate on z will only work with a perspective projection. But will be more complex to handle.

The easiest is to use glScaled(x,y,z) with x=y=z in your case. 1.O won’t change anything, 2.0 will enlarge to twice the size, 0.5 will reduce it etc.

Good luck !

glScale was just what I needed :slight_smile: Thank you all for the help.