I need to scale the result of glDrawPixels image.
I'm drawing a 640x480 pixels image buffer with glDrawPixels in a Qt QGLWidget.
I tryed to do the following in PaintGL:
glScalef(windowWidth/640, windowHeight/480, 0);
glDrawPixels(640,480,GL_RGB,GL_UNSIGNED_BYTE,frame);
But it doesn't work.
I am setting the OpenGL viewport and glOrtho with the size of the widget as:
void WdtRGB::paintGL() {
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Setup the OpenGL viewpoint
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, windowWidth, windowHeight, 0, -1.0, 1.0);
glDepthMask(0);
//glRasterPos2i(0, 0);
glScalef(windowWidth/640, windowHeight/480, 0);
glDrawPixels(640,480,GL_RGB,GL_UNSIGNED_BYTE,frame);
}
//where windowWidth and windowHeight corresponds to the widget size.
/the init functions are:
void WdtRGB::initializeGL() {
glClearColor ( 0.8, 0.8, 0.8, 0.0); // Background to a grey tone
/* initialize viewing values */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, windowWidth, windowHeight, 0, -1.0, 1.0);
glEnable (GL_DEPTH_TEST);
}
void WdtRGB::resizeGL(int w, int h) {
float aspect=(float)w/(float)h;
windowWidth = w;
windowHeight = h;
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
if( w <= h )
glOrtho ( -5.0, 5.0, -5.0/aspect, 5.0/aspect, -5.0, 5.0);
else
glOrtho (-5.0*aspect, 5.0*aspect, -5.0, 5.0, -5.0, 5.0);
//printf("\nresize");
emit changeSize ( );
}
It sounds like what you actually need to do instead of calling glDrawPixels () is to load your image data into a texture and draw a textured quad the size of the window. So something like this:
Or if that's too much work, glPixelZoom (windowWidth / 640, windowHeight / 480), might do the trick, too.