zoukankan      html  css  js  c++  java
  • OpenGL_赛平斯基垫片

    #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();          //进入循环

    }

  • 相关阅读:
    常用标点符号的英文名称
    2018年阅读随笔记录(持续更新)
    Lookahead and Lookbehind in Regex
    My Answer in Regex Golf
    Words to Use Instead of "Very"
    区块链
    EntityFramework Core 学习系列(一)Creating Model
    推送本地项目至Github遇到的问题以及解决办法记录
    TF-IDF In Scikit-Learn
    译MassTransit 创建消息消费者
  • 原文地址:https://www.cnblogs.com/Alip/p/5085458.html
Copyright © 2011-2022 走看看