Qt OpenGL默认比例确实很奇怪

发布于 2024-12-08 21:05:49 字数 1383 浏览 0 评论 0原文

我正在研究 Qt 编程书中的 OpenGL 示例。几乎一切都工作正常,但默认比例似乎相差甚远。我应该看到一个非常标准的立方体,但我看到的是这个。

wierdcube

我的立方体代码如下所示:

glBegin(GL_QUADS);

//top face
qglColor(m_faceColors[0]);
glVertex3f(-m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(m_cubeSize, m_cubeSize, m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, m_cubeSize);

// left face
qglColor(m_faceColors[1]);
glVertex3f(-m_cubeSize, -m_cubeSize, -m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, m_cubeSize);
glVertex3f(-m_cubeSize, -m_cubeSize, m_cubeSize);

依此类推...

我不会调用任何奇怪的 glScalef。我的 resizeGL() 看起来像这样:

void GLWidget::resizeGL(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    m_width = (height>0) ? (GLfloat)width/height : 1;
    glOrtho(-width, +width, -1.0, 1.0, -2, 2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

m_cubeSize 是 1.0

无论如何,当我在 draw() 函数中执行此操作时:

glScalef(275, 0.5, 0.5);

我看到这个(看起来正确):

propercube

有谁知道为什么默认情况下 x 比例会这么小?我完全按照书上说的做,但我真的很困惑。我之前(使用 Glut)做过相当多的 OpenGL,但这是我第一次使用 Qt 作为包装器。

I'm working on an OpenGL example out of a Qt programming book. Almost everything works fine, but the default scale seems to be way off. I should be seeing a pretty standard cube, but instead I see this.

wierd cube

My code for the cube looks like this:

glBegin(GL_QUADS);

//top face
qglColor(m_faceColors[0]);
glVertex3f(-m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(m_cubeSize, m_cubeSize, m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, m_cubeSize);

// left face
qglColor(m_faceColors[1]);
glVertex3f(-m_cubeSize, -m_cubeSize, -m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, -m_cubeSize);
glVertex3f(-m_cubeSize, m_cubeSize, m_cubeSize);
glVertex3f(-m_cubeSize, -m_cubeSize, m_cubeSize);

And so on...

I'm not calling any weird glScalef's. My resizeGL() looks like this:

void GLWidget::resizeGL(int width, int height)
{
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    m_width = (height>0) ? (GLfloat)width/height : 1;
    glOrtho(-width, +width, -1.0, 1.0, -2, 2);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}

m_cubeSize is 1.0

Anyway, when I do this in the draw() function:

glScalef(275, 0.5, 0.5);

I see this (looks correct):

proper cube

Does anyone know why the x scale would be so small by default? I'm doing exactly what the book says, but I'm really confused. I've done quite a bit of OpenGL before (with Glut), but this is my first time using Qt as a wrapper.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆伤 2024-12-15 21:05:49

您到底期望这个

glOrtho(-width, +width, -1.0, 1.0, -2, 2);

做什么?这样做不是更有意义吗:

glOrtho(-width, +width, -height, height, -2, 2);

What exactly do you expect this:

glOrtho(-width, +width, -1.0, 1.0, -2, 2);

to do? Wouldn't it make more sense to do something like this:

glOrtho(-width, +width, -height, height, -2, 2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文