如何在 beginNativePainting() 中翻转纹理?
我正在编写一个继承自QGLWidget的类:
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget *parent = 0);
~GLWidget();
void paintEvent(QPaintEvent *event);
private:
QImage* _frame;
};
GLWidget
的构造函数从磁盘加载图像,paintEvent()
负责使用在 beginNativePainting()
和 endNativePainting()
之间执行的本机 OpenGL 调用将数据发送到 GPU,并且工作正常。
问题是图像显示翻转(垂直),我需要解决这个问题。我还没有找到解决这个问题的方法,所以我希望有人可以帮助我解决这个问题。
在本机 Glut 应用程序中,我可以像这样简单地调用 glFrustum()
来进行翻转:
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, 1.0, -1.0, 10.0, 100.0 ); // flip vertically
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}
但我尝试在 beginNativePainting()
之后加载投影矩阵并调用 < code>glFrustum() 与上面的调用具有相同的值,我得到的只是黑屏(这意味着它没有按预期工作)。
有什么建议吗?
另外,使用QImage
的mirrowed(false, true)
方法进行翻转对图像的显示没有任何影响。
I'm writing a class that inherits from QGLWidget:
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
GLWidget(QWidget *parent = 0);
~GLWidget();
void paintEvent(QPaintEvent *event);
private:
QImage* _frame;
};
The constructor of GLWidget
loads an image from the disk, and paintEvent()
is responsible to send the data to the GPU using native OpenGL calls that are executed between beginNativePainting()
and endNativePainting()
, and this works OK.
The problem is that the image is being displayed flipped (vertically), and I need to fix this. I haven't found a way to this so I'm hoping somebody can help me on this issue.
In a native Glut application I could simply call glFrustum()
like this to do the flip:
static void Reshape( int width, int height )
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustum( -1.0, 1.0, 1.0, -1.0, 10.0, 100.0 ); // flip vertically
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0, -15.0 );
}
But I've tried loading the projection matrix after the beginNativePainting()
and calling glFrustum()
with the same values as the call above and all I get is a black screen (which means it didn't worked as expected).
Any tips?
Also, using the mirrowed(false, true)
method of QImage
to do the flipping didn't had any effect in the displaying of the image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要翻转投影,镜像纹理坐标。
顺便说一句:OpenGL 假定纹理图像数据的来源位于左下角(与大多数窗口系统相反,大多数窗口系统的来源位于左上角)。
Don't flip the projection, mirror the texture coordinates.
BTW: OpenGL assumes the origin of texture image data in the lower left corner (contrary to most windowing systems, which have it in the upper left).