views:

58

answers:

1

I am currently working on an in house GIS app. Background images are loaded in OpenGL by breaking the image down into what I guess are termed texels and mipmapped, after which a display list is built to texture map each texel onto rectangles. This sounds pretty standard, but the issue is that currently for images that do not divide neatly into 2^n pixel x 2^m pixel texels, the remainders are thrown away. Even if I were to capture the remainders and handle them in some way, I can't imagine that the answer is to continually test for texel subdivisions that eventually result in total capture of the image on neat boundaries? Or is it?

In some cases the images that I'm loading are geotiffs, and I need every single pixel to be included on my background. I've heard that glDrawPixels is slow. I know I could test this for myself, but I have a feeling that people in this space are using textures in opengl, not keeping track of pixel dumps.

I'm new to OpenGL, and I believe that the app is limiting itself to 1.1 calls.

I can post code if it will clairfy.

Thanks in advance!

+2  A: 

The standard way of handling non power of two images in OpenGL 1.1 is to store the image in a texture with dimension of the nearest larger power of two and then modifying the texture coordinates, some pseudocode:

float sMax = image.width / texture.width;
float tMax = image.height / texture.height;

glBegin(GL_QUADS);
glVertex2f(0, 0);
glTexCoord2f(sMax, 0);
glVertex2f(1, 0);
glTexCoord2f(sMax, tMax);
glVertex2f(1, 1);
glTexCoord2f(0, 0);
glVertex2f(0, tMax);
glTexCoord2f(0, 1);
glEnd();

With a higher version of OpenGL or if you're using extension you can use rectangular textures:

http://www.opengl.org/registry/specs/ARB/texture_rectangle.txt

Andreas Brinck
What a clear answer. Thanks!In your experience, does the answer change if the images are large? obviously for a gis app, you'll not just want to see it, but zoom to great depth. Currently I don't need to go 3d with my view. Is it sane to create a mipmap from one rather large texture made in the way you've described? (is using a mipmap even the proper approach?) Still an opengl newb.
Joshua
If you want to zoom out from the image you'll certainly want to create mipmaps to avoid sampling artifacts. I don't see any problem with creating mipmaps for the large texture.
Andreas Brinck
When you build a mipmap, you have to pass a pointer to your data. If you don't have enough data to fill a texture grid (because in this case I need to make a texture out of partial data) will build2dmipmaps puke? I'm noticing that my load routine pukes on build2dmipmaps when I get to the point in my loop where I am passing a pointer to some arbitrary NPOTS set of data, but I intend to map it to a POTS quad and modify texture maps later. Do you have any ideas?
Joshua