相关疑难解决方法(0)

通过OpenGL进行图像缩放(KeepAspectRatioByExpanding)

我正在尝试仅使用glTexCoord2f()glVertex2f()实现OpenGL中的图像缩放.

让我解释一下:在加载a QImage并将其发送到gpu后,glTexImage2D()我必须根据Qt的规范执行图像缩放操作.Qt定义了这3个操作(见下图):

在此输入图像描述

我认为这是唯一的方法,因为我的应用程序是一个Qt插件,这个任务需要paint()在类的方法内完成.这项IgnoreAspectRatio操作非常简单,现在正在运作.在KeepAspectRatio最初给了我一些麻烦,但现在它也在努力.不幸的是,KeepAspectRatioByExpanding让我很头疼.

我正在分享到目前为止我所做的事情,感谢您对此问题的帮助:

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();
}
Run Code Online (Sandbox Code Playgroud)

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()
{
}
Run Code Online (Sandbox Code Playgroud)

oglWindow.h:

#ifndef oglWindow_H …
Run Code Online (Sandbox Code Playgroud)

c c++ opengl qt image-scaling

17
推荐指数
2
解决办法
9403
查看次数

标签 统计

c ×1

c++ ×1

image-scaling ×1

opengl ×1

qt ×1