PDA

View Full Version : Partial image



PeterHer
12-10-2007, 05:08 AM
I am using glTextImage2D to diplay a very large image. The image is 8192 x 8192 pixels. The screen using is 2560 x 1600 pixels. Displaying the image is working very fine but now I want to display only a partial of that image.

Because the image will not fitt the screen the image is zoomed out using glScalef. So a lot of pixels are thrown away.

If I use glReadPixels (selecting a partial of the image displayed) and use glTextImage2D again I will miss a lot of information from the image. The only way I know how to solve this is to open de image file again, select the area of interest and use glTextImage2D to display the image. But this taks to much time.

Is there a better way to do this?

I also adjusted the glTexCoord2f paramaters but this wouldn't respect the aspectratio of the image. Because the selected portion of the image isn't square.

Thanks in advance.

Michael Steinberg
12-10-2007, 06:05 AM
I don't understand what you want to do.

PeterHer
12-10-2007, 07:00 AM
For example:

I have a screen of 1000 x 1000 pixels.
The image being displayed is 2000 x 2000 pixels.
The whole image can't be displayed because it is to big.
Scaling down the image with a factor 2 will result in an image that will fit the screen.

Now lets say I select an area (glReadPixels) of the displayed image. I select one quarter of the image. So this is an area of 500 x 500 pixels. But what I actualy want to do is selecting an area of 1000 x 1000 pixels. This way I have the full pixel information I need. Using glReadPixels will only give me the pixels being displayed, not the pixel information of one quarter of the original image.

Is there a way to get the full pixel information of the selected portion of the image?

Michael Steinberg
12-10-2007, 07:09 AM
I don't exactly know why you dont just take the data directly from the image itself, but glTexcoord will help you to scale the texture accordingly to what you want to see on the screen.

Say your Viewport size is 1000x1000 pixels, your texture is 2000x2000 texels. If you want to see the upper left quad of the texure 1:1, then you set the texcoords of your fullscreen-quad accordingly (texccoords of the upper left corner (0.0; 1.0), lower right (0.5; 0.5)). Possibly i missed some rounding issue here... You could also setup the Texture Matrix in such a way, that you can specify the Texcoords in a Texel-fashion...

Or another way is setting up your Projection so that 1.0f distance in either direction means 1 Pixel on the screen and your textured Quad has the dimensions of the texture itself...

PeterHer
12-10-2007, 07:39 AM
Taking the data directly from the image itself takes to much time. I have to copy the selected area to a new buffer and use glTexImage2D again to update the information.

Can't use TexCoords. What happens if the selected area isn't square. The aspect ratio isn't right.

The whole picture is this:

One window on screen (WholeImage) will display the whole image.
Another window (ZoomImage) on the screen will display the
selected area in the WholeImage window.
Like some kind of a magnifying glass. Moving the magnifying glass around in the WholeImage must update the ZoomImage very quickly.

Michael Steinberg
12-10-2007, 07:49 AM
Can't use TexCoords. What happens if the selected area isn't square. The aspect ratio isn't right.


Simply take the aspect ratio into account when calculating the texcoords? oO



Like some kind of a magnifying glass. Moving the magnifying glass around in the WholeImage must update the ZoomImage very quickly.


I didnt mean the displaying, but why do you need glReadpixels there? That sounded to me, like you wanted to extract a rectangle of an image through loading that image to the gpu, rendering and then reading the result back from the gpu, which sounds....cumbersome^^

Jan
12-10-2007, 07:57 AM
Simply render one quad in the background with texcoords set to display the whole image. And then render a quad in the foreground, where your magnifying glass should be, and use other texcoords to "zoom in" on the image. No readpixels needed at all, no reading from file, no updating any buffers.

Since you seem not to have understood the basics of texture-mapping (especially how texcoords work), i suggest you read up on that or take a look at a few more tutorials. Once you have understood those concepts, it will be very easy to achieve your goal.

Jan.