I'm trying to implement image scaling in OpenGL using only glTexCoord2f() and glVertex2f().

Let me explain: after loading a QImage and sending it to the gpu with glTexImage2D() I have to perform image scaling operations based on Qt's specification. Qt defines these 3 operations (see image below):

enter image description here

I think this is the only way to do it since my application is a Qt plugin and this task needs to be done inside the paint() method of the class. The IgnoreAspectRatio operation is pretty straight forward and it's working right now. The KeepAspectRatio gave me some trouble initially but now it's also working. Unfortunally, KeepAspectRatioByExpanding is giving me headaches.

I'm sharing what I've done so far and I appreciate your help on this issue:

main.cpp:

#include "oglWindow.h"
#include <QtGui/QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    oglWindow w;
    w.show();
    return a.exec();
}

oglWindow.cpp:

#include "oglWindow.h"
#include "glwidget.h"

#include <QGridLayout>

oglWindow::oglWindow(QWidget *parent, Qt::WFlags flags)
    : QMainWindow(parent, flags)
{
    ui.setupUi(this);
    GLWidget *openGL = new GLWidget(this);

    QGridLayout *layout = new QGridLayout;
    setLayout(layout);
}

oglWindow::~oglWindow()
{
}

oglWindow.h:

#ifndef oglWindow_H
#define oglWindow_H

#include <QtGui/QMainWindow>
#include "ui_yuv_to_rgb.h"

class oglWindow : public QMainWindow
{
    Q_OBJECT

public:
    oglWindow(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~oglWindow();

private:
    Ui::oglWindowClass ui;
};

#endif /
Edit
Report