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

    }

  • 相关阅读:
    jqgrid 获取选中用户的数据插入
    jqgrid 自定义文本框、选择框等查询
    Java学习—— for循环
    Android中 Http请求
    异步消息处理机制——Handler用法
    ThreadLocal
    Android开发 学习笔记——HelloWorld
    eclipse 常用插件
    mysql 命令备份还原
    学习
  • 原文地址:https://www.cnblogs.com/Alip/p/5085458.html
Copyright © 2011-2022 走看看