我想显示从 - ( - 50,-50,-50)延伸到(50,50,50)的盒子的5个边(仅显示顶侧)。我的立方体绘图功能如下:
void drawRectangularPrism(Coordinate corner, Coordinate dimensions)
{
glPushMatrix();
glBegin(GL_QUADS);
// back face
glNormal3f(0, 0, 1);
glVertex3f(corner.x, corner.y, corner.z);
glVertex3f(corner.x + dimensions.x, corner.y, corner.z);
glVertex3f(corner.x + dimensions.x, corner.y + dimensions.y, corner.z);
glVertex3f(corner.x, corner.y + dimensions.y, corner.z);
// bottom face
glNormal3f(0, 1, 0);
glVertex3f(corner.x, corner.y, corner.z);
glVertex3f(corner.x, corner.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y, corner.z);
// top face
glNormal3f(0, -1, 0);
glVertex3f(corner.x, corner.y + dimensions.y, corner.z);
glVertex3f(corner.x, corner.y + dimensions.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y + dimensions.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y + dimensions.y, corner.z);
// right face
glNormal3f(-1, 0, 0);
glVertex3f(corner.x + dimensions.x, corner.y, corner.z);
glVertex3f(corner.x + dimensions.x, corner.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y + dimensions.y, corner.z + dimensions.z);
glVertex3f(corner.x + dimensions.x, corner.y + dimensions.y, corner.z);
// left face
glNormal3f(1, 0, 0);
glVertex3f(corner.x, corner.y, corner.z);
glVertex3f(corner.x, corner.y, corner.z + dimensions.z);
glVertex3f(corner.x, corner.y + dimensions.y, corner.z + dimensions.z);
glVertex3f(corner.x, corner.y + dimensions.y, corner.z);
glEnd();
glPopMatrix();
}
如果它有用,这是我设置OpenGL渲染的函数:
void init()
{
glClearColor(1.0, 1.0, 1.0, 1.0); // Clear the background of our window to white
GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}, shininess[] = {50.0}, emission[] = {0.0, 0.0, 0.0, 1.0},
lightPosition[] = {1.0, 1.0, 1.0, 0.0}, lightAmbient[] = {0.0, 0.0, 0.0, 1.0},
lightDiffuse[] = {1.0, 1.0, 1.0, 1.0}, lightSpecular[] = {1.0, 1.0, 0.0, 1.0};
glShadeModel(GL_SMOOTH);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, emission);
glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
glEnable(GL_LIGHT0);
//glEnable(GL_DEPTH_TEST); // makes objects overlap correctly / or not?!
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_CULL_FACE); // makes it faster?!
}
最终结果:
为什么不显示多维数据集的顶部和左侧?
答案 0 :(得分:3)
顶部/底部,左/右面对仅因偏移而异,这表示您未考虑顶点绕组顺序。请先查看glFrontFace
。
答案 1 :(得分:0)
你的四边形最有可能被
淘汰glEnable(GL_CULL_FACE);
删除它,它应该工作