赞
踩
#include <GL/glut.h>
#include<Windows.h>
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,-2.5f);//下点
glVertex2f (1.0f,0.0f);//右点
glVertex2f (0.0f, 2.5f);//上点
glVertex2f (-1.0f,0.0f);//左点
glEnd ( );
}
void myDisplay(void)
{
glClear (GL_COLOR_BUFFER_BIT); //清空
glLoadIdentity(); //将当前矩阵设为单位矩阵
glRotatef(45,0.0,0.0,1.0);//顺时针旋转45度
glTranslatef(0.0,2.5,0.0);
glColor3f(0.0,1.0,0.0);
drawDiamond();
glLoadIdentity(); //将当前矩阵设为单位矩阵
glRotatef(135,0.0,0.0,1.0);//顺时针旋转135度
glTranslatef(0.0,2.5,0.0);
glColor3f(0.0,1.0,0.0);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。