#!/usr/bin/perl -w
use strict;
use warnings;
use OpenGL qw/ :all /;
use OpenGL::Config;
glutInit();
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
glutInitWindowPosition(100,100);
glutInitWindowSize(400,400);
glutCreateWindow("opengl");
glClearColor(0,255);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(-100,100,-100,100);
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc(&;mydis);
glutMainLoop();
return 0;
sub mydis()
{
glClearColor(0,255);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
glColor3f(1,1,1);
glBegin(GL_LINES);
glVertex2f(-100,0);
glVertex2f(100,0);
glEnd();
glBegin(GL_LINES);
glVertex2f(0,-100);
glVertex2f(0,100);
glEnd();
# 画矩形
glColor3f(0.5,0.1,0);
glRecti(-50,-50,50,50);
glFlush();
glPushMatrix();
#向x方向移动3.5个单位,y方向移动8.5个单位
glColor3f(0.1,0.9);
glTranslatef(3.5,8.5,0);
glRecti(-50,50);
glFlush();
glPopMatrix();
glPushMatrix();
#x方向放大到1.2倍,y方向放大到1.8倍
glColor3f(0.1,0.9,0.1);
glScalef(1.2,1.8,1);
glRecti(-50,50);
glFlush();
glPopMatrix();
glPushMatrix();
#x方向缩小至0.5倍,y方向缩小至0.8倍
glColor3f(0.9,0.9);
glScalef(0.5,0.8,50);
glFlush();
glPopMatrix();
glPushMatrix();
#二维旋转,相对于坐标原点的
glColor3f(0.7,0.7);
my ($x1,$y1,$x2,$y2)=(15,15,50);
for (my $theta=5;$theta<360;$theta+=5)
{
glRotatef($theta,1);#相对于z轴
glRecti(-50,50);
}
glFlush();
}

(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|