Qt OpenGL default scale is really strange
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开发者_C百科, 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.
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);
精彩评论