glPixelZoom

Hey everyone,

I need to zoom into a bitmap using OpenGL for my application. Currently, I am using a call to glPixelZoom before calling the glDrawPixels function.

I was wondering if this is a good way to achieve this. Just wanted the general consensus and view as I am quite a begineer with OpenGL.

Cheers,
xargy

No, this is a pretty bad way, the image data gets sent over the bus each time, and probably reformatted, the zoom factor has limits and the filtering probably sucks.

Load your image to a texture, once you have a texture the image will be on the graphics card or other suitable fast memory for use in all subsequent zoom operations. You can then apply a texture GL_LINEAR magnification filter for bilinear filtering during the zoom, or GL_NEAREST for point sampling.

Simply draw a textured quad with suitable texture coordinates to apply your image zoom, this will also give you the fastest possibe results since a lot of graphics hardware is pretty much dedicated to this type of operation.

Hi Dorbie,

Thanks for the reply. Is there a zooming function available through OpenGL that I can use on the texture or do I have to implement the zooming functionality myself. The reasom I chopse glPixelZoom was that I did not have to code any zooming functions myself.

Thanks and cheers,
xargy

ok, never mind the zooming question. I see what you mean.

Cheers,
xargy

Hi everyone,

Ok, am having trouble drawing the textured image
to the screen. Here is how I am using it right now:

// Creating the texture
glGenTextures(1, &m_Texture);
glBindTexture(GL_TEXTURE_2D, m_Texture);
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.bmWidth,
bitmap.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
bitmap.bmBits);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

Now I have an OpenGl window of given width and height. What I want to
do is draw the texture into this OpenGL screen. So; I try:

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_Texture);

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(0, height);

    glTexCoord2i(1, 0); 
    glVertex2i(width, height); 

    glTexCoord2i(1, 1); 
    glVertex2i(width, 0); 

    glTexCoord2i(0, 0); 
    glVertex2i(0, 0); 

glEnd();
glDisable(GL_TEXTURE_2D);

This, however just colors my screen with a white background and does not draw the texture. I would really appreciate some help here.

Thanks and cheers,
xargy

Hi,

Do you guys think it could be because the texture size is not a power of 2? I am trying to load images and have no control over the sizes. If that is a limitation, then I have to fall back to some other method for zooming.

Cheers,
xargy

Ok, one thing that was a mistake was the last section of quad drawing. It should have been:

glTexCoord2i(0, 1);
glVertex2i(0, 0);

The problem seems to be the size of the image. I created a 256 X 256 texture and that loads and displays just fine.

So, does anyone know how I can load an arbitrary size image into a texture?

Thanks and cheers,
xargy

ok, used the gluBuild2DMipmaps function.

cheers,
xarg