PDA

View Full Version : Zooming and Panning



kanet77
03-24-2003, 01:35 PM
Hello, and welcome to my post. Make yourself at home. If you have some experience using glDrawPixels() I'd like to hear from you.

I'm using glDrawPixels() to display a bitmap (actually two because I'm in stereo mode). I'm supporting pan and zoom operations on the image. I need to control the positioning of the drawn image down to the screen pixel. This means that I sometimes need to start drawing in the middle of an image pixel. However, glDrawPixels doesn't support this functionality, so instead I "shift" the whole image by starting to draw outside the window.

At first I couldn't start drawing outside the left or the bottom of the window. I used a trick with glBitmap() I found online to allow me to draw from outside the window. ( http://www.frii.com/~martz/oglfaq/clipping.htm -- Question 10.070) But it appears that I can't draw to the entire window if I do this. For example, if I start drawing from x = -10 (10 pixels outside the left window edge), the 10 rightmost pixels of the window will not be drawn to. This is exactly the same problem that occurs when the window is dragged off the left or bottom edge of the screen. So I guess this glBitmap() trick ensures that something is drawn rather than drawing nothing due to an invalid raster position. But if I can't draw to the entire window I really don't see the point.

I'm currently trying to get around this problem by using glDrawPixels() to draw the image in sections. I suppose this is a workable solution although it involves more calculations and I'm concerned about the inefficiency of calling glDrawPixels() four times. Especially when I draw the "column" on the right edge of the screen because these pixels are not in contiguous memory.

Has anyone had a similar problem? Thanks for any input.

-tom

JustHanging
03-24-2003, 01:41 PM
Hi,

I haven't had such problems, propably because I try to avoid using glDrawPixels. It's slow and a bit difficult for reasons you just explained. Usually it's a much better idea to make textures out of those images and draw them as textured quads. It's a lot faster and you no longer have to worry about clipping and zooming. With proper filtering you should get your sub-pixel accuracy too.

-Ilkka

kanet77
03-24-2003, 03:59 PM
Originally posted by JustHanging:
Hi,

I haven't had such problems, propably because I try to avoid using glDrawPixels. It's slow and a bit difficult for reasons you just explained. Usually it's a much better idea to make textures out of those images and draw them as textured quads. It's a lot faster and you no longer have to worry about clipping and zooming. With proper filtering you should get your sub-pixel accuracy too.

-Ilkka

The images I'm dealing with can be very large so I was hoping to avoid using textured quads. However, I am seriously considering it and I started writing code to do just that after I posted this. I've been banging my head against glDrawPixels() for a while.

But as far as glDrawPixels() being slow I'm not sure I agree. If I go ahead with the textured quad plan I can do some benchmarking and find out, but it seems plenty fast. For one thing, I disabled a lot of things that slow it down.

And I think I'll ask this question now so I'm prepared: What do you mean by 'proper filtering'?

Thanks for the input, Ilkka,
-tom

john
03-24-2003, 09:53 PM
Filtering (I have no idea what a "proper" filter is) will fit a function through points and give you something that isn't nearest neighbour, but there is no way that filtering will completely undo downsampling a large image to texture dimensions.

You'll _never_ get back your original data with filtering.

JustHanging
03-25-2003, 12:45 AM
Proper in this case is nothing but GL_LINEAR or GL_LINEAR_MIPMAP_LINEAR. I wasn't talking about downsampling but the fact, that if you use linear filtering you can move the image less than 1 pixel/frame and you'll get smooth motion. Basically for 2d images, using linear filtering gives the same result as oversampling, only a lot faster.

-Ilkka