Auto downsampling using OpenGL?

Hi,

I have a 400x400 RGB array

I would like to use drawPixel to draw on the screen with resolution (200x200, 300x300, etc.)

Is it possible to do this automatically?

Thanks. :slight_smile:

Yes, use glOrtho projection along with glTexImage2D (to load the texture). Then all you need to do is map the texture to the size of quad you want to use.

Of course power of 2 dimensions may be a factor if your video card does not support one of the texture rectangle extensions.

but glTexImage2D seems only support texture with same width and height?

how about if my image is to resize to, say, 400x200 -> 200x100

how to maintain the aspect ratio?

thanks :slight_smile:

I finally find out that the drawPixel wll auto convert to fit the viewport for me:

e.g.

glDrawPixels( WindowWidth, WindowHeight, GL_RGB, GL_FLOAT, frameBuffer);

where

frameBuffer = float[ WindowWidth * x * WindowHeight * y * 3]

x & y = 1,2,3,…

but using this approach, will there be any side effect?

:slight_smile:

but using the above approach does not take the advantage of higher resolution, say for antialiasing

Or any simple method to enhance the scale down effect?

thanks.

If your card/driver supports ARB_texture_rectangle then glTexImage2D can load a non power of 2 2D texture. With or without the extension the dimensions do not have to be the same. If it doesn’t support one of the texture_rectangle extensions then the width and height must be a power of 2 though not necessarily the same.