OpenGL--实践(一)

按下图所示依次绘制出10种基本图元的图形,开启点、线、多边形抗锯齿,并且绘制多边形时在不同顶点指定不同颜色使多边形呈渐变色彩。

图元GL_POINTS的绘制
glPointSize(5.0f); //设置点的大小
glBegin(GL_POINTS);
glColor3f(1, 1, 0);
glVertex2f(0, 0);
glVertex2f(0.1, -0.1);
glVertex2f(0.2, -0.1);
glVertex2f(0.3, 0);
glVertex2f(0.4, 0.1);
glEnd();

 

 


//线的绘制
glLineWidth(0.5f);    //设置线的宽度
glBegin(GL_LINES);
glColor3f(1, 1, 0);
glVertex2f(0, 0);
glVertex2f(0.5, 0.2);

glColor3f(1, 0, 0);
glVertex2f(0.4, 0.1);
glVertex2f(1.0, -0.1);


glColor3f(1, 0, 1);
glVertex2f(0.2, -0.2);
glVertex2f(0.6, -0.3);

glColor3f(0, 0, 1);
glVertex2f(0.1, -0.3);
glVertex2f(0.6, -0.15);

glEnd();

	//画线段
glLineWidth(0.5f);
glBegin(GL_LINE_STRIP);
glColor3f(1, 1, 0);

glVertex2f(0, 0);
glVertex2f(0.7,-0.4);
glVertex2f(0.6, -0.1);
glVertex2f(0.1,-0.2);
glVertex2f(0.05,-0.4);

glEnd();

 

glBegin(GL_LINE_LOOP);
glLineWidth(0.5f);
glColor3f(1, 1, 0);
glVertex2f(0, 0);
glVertex2f(0.2, -0.4);
glVertex2f(0.7, -0.4);
glVertex2f(0.6, -0.03);
glVertex2f(0.5, -0.3);
glVertex2f(0.3, 0.2);
glEnd();

//GL_POLYGON
glBegin(GL_POLYGON);
glColor3f(1, 1, 0);
glVertex2f(0, 0);
glColor3f(1, 0, 0);
glVertex2f(0.7,0.2);
glColor3f(0, 0, 1);
glVertex2f(0.6,-0.3);
glColor3f(1, 0, 1);
glVertex2f(-0.05, -0.5);
glColor3f(0, 1, 1);
glVertex2f(-0.1, -0.3);
glEnd();

 

 

glBegin(GL_QUADS);  //图元
glColor3f(0, 1, 0);
glVertex2f(0, 0);
glColor3f(1, 0, 0);
glVertex2f(0.1, 0.15);
glColor3f(0, 0, 1);
glVertex2f(0.4, 0.2);
glColor3f(1, 0,1);
glVertex2f(0.45, -0.1);

glColor3f(0, 0, 1);
glVertex2f(0.5, -0.2);
glColor3f(1, 0, 1);
glVertex2f(0.6, 0.25);
glColor3f(1, 0, 0);
glVertex2f(0.9, 0.4);
glColor3f(0, 1, 0);
glVertex2f(0.7, -0.2);
glEnd();

glBegin(GL_QUAD_STRIP);  //图元
glColor3f(1, 0, 0);
glVertex2f(0, 0);
glColor3f(0, 1, 0);
glVertex2f(-0.05, 0.3);

glColor3f(1, 1, 0);
glVertex2f(0.27, 0);

glColor3f(0, 0, 1);
glVertex2f(0.3, 0.33);

glColor3f(0, 1, 1);
glVertex2f(0.7, 0.03);
glColor3f(1, 0, 1);
glVertex2f(0.6, 0.4);

glColor3f(0, 0, 1);
glVertex2f(0.8, 0.06);
glColor3f(1, 1, 0);
glVertex2f(0.78, 0.5);


glEnd();

 

glBegin(GL_TRIANGLES);
glColor3f(1, 1, 0);
glVertex2f(0, 0);
glColor3f(0, 0, 1);
glVertex2f(0, 0.3);
glColor3f(0, 1, 0);
glVertex2f(0.4, 0);
glColor3f(1, 0, 1);
glVertex2f(0.4, 0.2);
glColor3f(0, 1, 1);
glVertex2f(0.1, 0.5);
glColor3f(1,0,0);
glVertex2f(0.7, 0.5);

glEnd();

glBegin(GL_TRIANGLE_STRIP);
glColor3f(1, 1, 0);
glVertex2f(0, 0.3);
glColor3f(1, 0, 1);
glVertex2f(0, 0);
glColor3f(0, 1, 1);
glVertex2f(0.3, 0.3);
glColor3f(1, 0, 0);
glVertex2f(0.4,0);
glColor3f(1, 0, 1);
glVertex2f(0.5, 0.3);
glColor3f(1, 1, 0);
glVertex2f( 0.6, - 0.1);
glEnd();

 

 

glBegin(GL_TRIANGLE_FAN);
glColor3f(1, 0, 0);
glVertex2f(0, 0);
glColor3f(1, 0, 1);
glVertex2f(0, 0.4);
glColor3f(1, 1, 0);
glVertex2f(0.3, 0.3);
glColor3f(1, 0, 0);
glVertex2f(0.5, 0.04);
glColor3f(0, 1, 0);
glVertex2f(0.47, -0.23);

glEnd();

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值