Handling big images


I’m trying to write a program that displays images.
It should be possible to rotate (90 degree steps only),
zoom in and out and move the images inside the window.

My problem is, that these images are very big and I my
program segfaults, when I try to load them as textures.

I also tried glDrawPixels but when displaying the whole
image and moving it around it gets very slowly.

Is there a way to especially move such a big image


can you post some code? and can you tell how big is “very big”? you can use glGet(GL_MAX_TEXTURE_SIZE, …) to determine the maximum texture size that your gl implementation allows.

How about partitioning the whole image into multiple grids(rectangles). And apply them as textures on adjacent multiple quads(planes).

Doing this, video driver may load/unload the textures automatically for you if they cannot fit on memory capacity.

You may notice a hiccup caused by delaying of loading textures into memory if the whole textures cannot be loaded on video memory.

One of the images has a size of 2953x2479 pixels and a resolution
of 300 dpi. It is a tif-image which needs 22Mb disk space.
And it is possible, that there will be even bigger ones.

What code do you want to see? As I wrote above, I simply tried
something like this:


if (img) {
    glRasterPos2f(ox, h-oy);
    glPixelZoom(scale, scale);
    glDrawPixels(img->GetWidth(), img->GetHeight(), GL_RGB, GL_UNSIGNED_BYTE, img->GetData());

Here I have the problem, that the image isn’t drawn, when the
origin of the image has a negative value. I don’t know how to fix
this, but because I didn’t know, if I will later still use
glDrawPixels I left this bug in the test version.

But what if the whole image can be seen? Then the whole image has
to be loaded as well. And this is the case when it gets slowly.
When the zoom factor is higher and only a small part of the
image can be seen, then the performance is ok.

When do you use this 2953x2479 image as a texture do you resize it?

Remember that a normal texture must have power of two dimensions.


No, I used this function
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

to bypass the restriction. And this worked for an image
with a 200x200 resolution.

hm…concerning the visibility: afaik, the position which you define with glRasterPos must be inside the viewport (after being transformed with the modelview and projection matrices), otherwise the image is not drawn.

just a thought- try to scale the image- in both directions- to have a size dividable by 8.

Swald, as API hinted at, you should probably be using a texture to draw your stuff, not DrawPixels (very slow by comparison). You can map in portions of the image as needed/viewed with glTexSubImage for example.

With this basic technique the texture size is virtually unlimited. You could use this in conjunction with Songho’s grid idea and display massive images indeed.