Qt OpenGL默认比例确实很奇怪
我正在研究 Qt 编程书中的 OpenGL 示例。几乎一切都工作正常,但默认比例似乎相差甚远。我应该看到一个非常标准的立方体,但我看到的是这个。
我的立方体代码如下所示:
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);
我看到这个(看起来正确):
有谁知道为什么默认情况下 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.
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):
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您到底期望这个
做什么?这样做不是更有意义吗:
What exactly do you expect this:
to do? Wouldn't it make more sense to do something like this: