我正在尝试使用 GL_TRIANGLE_STRIP 绘制一条线,该线会随着 z 坐标变深或更浅,但是我传递给 glVertex3f() 的 z 值似乎不会影响感知的宽度。在下面的代码中(来自 OpenGL 编程指南的修改示例),该线应该从更接近透视图开始(更大),并变得更远(更小)。
你会指出我的错误,还是解决这个问题的主题?
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
}
void display(void)
{
GLdouble gran = 5.0;
GLdouble width = 7.0;
GLdouble theta = 1.047197551;
GLdouble halfPi = 3.1459/2;
GLdouble refpx = 50.0;
GLdouble refpy = 50.0;
GLdouble startr = 1.0;
GLdouble startg = 1.0;
GLdouble startb = .5;
glClear(GL_COLOR_BUFFER_BIT);
//glLoadIdentity();
//glScalef(2.0, -.5,1.0);
//glRotatef(45.0, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLE_STRIP);
for(int i = 0; i < 40; i++)
{
glColor3f(startr / i, startg / (20 - (i%20)), startb);
GLdouble x1 = refpx + width*cos(theta + halfPi);
GLdouble x2 = refpx + width*cos(theta + halfPi*3);
GLdouble y1 = refpy + width*sin(theta + halfPi);
GLdouble y2 = refpy + width*sin(theta + halfPi*3);
glVertex3f(x1,y1, (GLdouble)i/40.0);
glVertex3f(x2,y2, (GLdouble)i/40.0);
refpx += gran*cos(theta);
refpy += gran*sin(theta);
if(i % 9 == 0) {
theta += halfPi/8;
}
if(i == 20) {
theta -= halfPi/2;
}
if(i == 5) {
theta -= halfPi/2;
}
}
glEnd();
glDisable(GL_BLEND);
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, (GLdouble) w, 0.0, (GLdouble) h, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(450, 450);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}