赛平斯基垫片



#include "stdafx.h"

#include <GL/glut.h>

#include <stdlib.h>          //包含random函数

void myInit(void)

{  glClearColor(1.0, 1.0, 1.0, 0.0);     //设置背景颜色为白  

glColor3f(0.0f, 0.0f, 0.0f);      //设置绘图颜色为黑  

glPointSize(2.0);         //设置点大小  

glLineWidth(10.0);         //设置线宽  

glMatrixMode(GL_PROJECTION);      //设置合适的矩阵  

glLoadIdentity();  gluOrtho2D(0.0, 640.0, 0.0, 600.0);     //建立一个坐标系

}

 

struct GLPoint

{  GLfloat x, y; };

void sierpinski_render(void)

{  glClear(GL_COLOR_BUFFER_BIT);        //清屏  

GLPoint T[3] = { { 10, 10 }, { 600, 10 }, { 300, 600 } }; //定义三角形顶点  

int index = rand() % 3;          //随机选择初始顶点  

GLPoint point = T[index];         //生成一个含3个顶点的数值  

glBegin(GL_POINTS);  for (int i = 0; i < 55000; i++)        //画55000个点

 {  

 index = rand() % 3;   

point.x = (point.x + T[index].x) / 2;   

point.y = (point.y + T[index].y) / 2;   

glVertex2i(point.x, point.y);    

}  

glEnd();  

glFlush();

}

int main(int argc, char *argv[])

{

 glutInit(&argc, argv);        //初始化工具包

 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);  //设置显示模式

 glutInitWindowPosition(100, 100);     //设置屏幕上窗口位置

 glutInitWindowSize(400, 400);      //设置窗口大小

 glutCreateWindow("第一个OpenGL程序");    //打开代表提的窗口

 glutDisplayFunc(sierpinski_render);     //注册重画回调函数(sierpinski_render)  //glutDisplayFunc(myDisplay);       //注册重画回调函数(mydisplay)  myInit();

 glutMainLoop();          //进入循环

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值