perl-opengl立方体
程序员文章站
2022-04-29 13:23:02
...
#!/usr/bin/perl -w use strict; use warnings; use OpenGL qw/ :all /; use OpenGL::Config; my @mypoints; @mypoints=([0,0,0],[0,50,0],[50,0,0],[50,50,0],[0,0,50],[0,50,50],[50,0,50],[50,50,50]); glutInit(); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowPosition(100,100); glutInitWindowSize(400,400); glutCreateWindow("my OpenGL program"); glClearColor(0,0,0,255); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glOrtho(-100,100,-100,100,-100,100); glMatrixMode(GL_MODELVIEW); glutDisplayFunc(\&mydis); glutMainLoop(); return 0; sub mydis() { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); gluLookAt(-1,-1,-5,0,0,0,5,0,0); glColor3f(255,255,0); &quad(6,2,3,7); &quad(5,1,0,4); &quad(7,3,1,5); &quad(4,0,2,6); &quad(2,0,1,3); &quad(7,5,4,6); glFlush(); } sub quad() { my @ptn=@_; glBegin(GL_QUADS); glVertex3i(@{$mypoints[$ptn[0]]}); glVertex3i(@{$mypoints[$ptn[1]]}); glVertex3i(@{$mypoints[$ptn[2]]}); glVertex3i(@{$mypoints[$ptn[3]]}); glEnd(); }