opengl实验3的作业答案

实验三的作业:

绘制如下图形:


201210302208378962.jpg (257×268)
提示:

(1)写一个绘制菱形的函数drawDiamond(void);

void drawDiamond(void) //绘制中心在原点的菱形

{

glBegin (GL_POLYGON); //顶点指定需要按逆时针方向

glVertex2f (0.0f,-1.0f);//下点

glVertex2f (2.0f,0.0f);//右点

glVertex2f (0.0f, 1.0f);//上点

glVertex2f (-2.0f,0.0f);//左点

glEnd ( );

}


void init (void)


{


glClearColor (1.0, 1.0, 1.0, 0.0);


glMatrixMode (GL_PROJECTION);


gluOrtho2D (-5.0, 5.0, -5.0, 5.0); //设置显示的范围是X:-5.0~5.0, Y:-5.0~5.0


glMatrixMode (GL_MODELVIEW);


}


void drawDiamond(void) //绘制中心在原点的菱形


{


glBegin (GL_POLYGON); //顶点指定需要按逆时针方向


glVertex2f (0.0f,-1.0f);//下点


glVertex2f (2.0f,0.0f);//右点


glVertex2f (0.0f, 1.0f);//上点


glVertex2f (-2.0f,0.0f);//左点


glEnd ( );


}


void myDraw (void)


{


glClear (GL_COLOR_BUFFER_BIT); //清空


glLoadIdentity();


glColor3f(0.0,0.0,1.0);


drawDiamond();


glRotatef(90,0.0,0.0,1.0);


glTranslatef(1.0,0.0,0.0);


glColor3f(1.0,0.0,0.0);


drawDiamond();


glLoadIdentity();


glTranslatef(-1.78,-2.0,0.0);


glRotatef(30.0,0.0,0.0,1.0);


glColor3f(0.0,1.0,0.0);


drawDiamond();


glLoadIdentity();


glTranslatef(1.78,-2.0,0.0);


glRotatef(-30.0,0.0,0.0,1.0);


glColor3f(0.0,1.0,1.0);


drawDiamond();


glFlush ( );




}


void main (int argc, char** argv)


{


glutInit (&argc, argv);


glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);


glutInitWindowPosition (0, 0);


glutInitWindowSize (600, 600);


glutCreateWindow ("几何变换函数综合示例");


init();


glutDisplayFunc (myDraw);


glutMainLoop ( );


}


我的实验效果图:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值