• OpenGL_恐龙


    #include "stdafx.h"

    #include <GL/glut.h>

    #include <iostream>

    #include <fstream>

    using namespace std;

    void myInit(void)

    {  

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

    glColor3f(0.0f, 0.0f, 0.0f);        //画图颜色为黑;  

    glLineWidth(1.0);           //笔触大小为1像素;  

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

    glLoadIdentity();  

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

    }

    void drawPolyLineFile(void)

    {  

    glClear(GL_COLOR_BUFFER_BIT);        //清屏;  

    fstream inStream;  

    inStream.open("D:\VS Projects\ALip_a4_drawDinosaur\dino.dat", ios::in);     //打开文件;  

    if (inStream.fail())   

    return;  

    GLint numPolys, numLines, x, y;      //总共线条的个数,折线的点数,第一个点,第二个点;  

    inStream >> numPolys;          //读折线数量;  

    for (int j = 0;

    j < numPolys; j++)       //读每条折线;  

    {   

    inStream >> numLines;   

    glBegin(GL_LINE_STRIP);         //画下一条折线;  

     for (int i = 0; i < numLines; i++)   

    {    

    inStream >> x >> y;         //读下一对x,y;    

    glVertex2i(x, y);   

    }   

    glEnd();  

    }  

    glFlush();             //送所有数据到显示;  inStream.close(); }

    void main(int argc, char** argv)

    {  

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

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

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

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

    glutCreateWindow("恐龙");         //打开屏幕窗口;  

    glutDisplayFunc(drawPolyLineFile);       //注册重画函数;  

    myInit();  

    glutMainLoop();            //进入永久循环;

    }

    输入数据(dino.dat)

    21
    29
    32 435
    10 439
    4 438
    2 433
    4 428
    6 425
    10 420
    15 416
    21 413
    30 408
    42 406
    47 403
    56 398
    63 391
    71 383
    79 369
    84 356
    87 337
    89 316
    88 302
    86 294
    83 278
    79 256
    78 235
    79 220
    85 204
    94 190
    98 183
    98 182
    9
    116 189
    105 184
    98 172
    98 156
    93 141
    93 132
    99 122
    104 115
    104 114
    38
    153 116
    152 112
    153 107
    154 93
    154 81
    152 67
    146 56
    140 47
    136 39
    133 30
    130 17
    128 7
    127 3
    93 2
    93 10
    96 16
    96 20
    97 21
    101 24
    104 27
    105 31
    107 36
    108 40
    109 47
    111 51
    114 58
    118 66
    120 71
    118 79
    117 88
    116 97
    112 105
    107 113
    107 118
    108 126
    112 138
    116 146
    118 148
    7
    153 95
    158 99
    159 103
    161 108
    161 115
    160 121
    160 122
    7
    156 80
    167 79
    182 76
    203 73
    220 78
    235 79
    239 80
    43
    262 154
    259 141
    259 123
    257 110
    255 93
    259 86
    272 74
    287 46
    290 41
    299 30
    305 21
    307 15
    307 12
    300 11
    299 9
    301 2
    303 1
    313 5
    320 7
    307 1
    312 0
    321 0
    325 0
    331 0
    336 2
    336 8
    334 18
    335 24
    331 29
    327 39
    323 45
    317 54
    312 63
    308 70
    301 79
    297 86
    296 97
    300 109
    303 120
    304 126
    307 138
    306 148
    305 152
    5
    298 86
    304 92
    310 104
    314 114
    314 119
    7
    255 98
    251 100
    246 105
    242 112
    236 122
    231 131
    233 126
    7
    271 73
    264 74
    257 76
    244 76
    236 80
    231 84
    230 86
    24
    242 77
    242 70
    245 61
    246 49
    248 39
    249 30
    248 19
    245 12
    242 9
    241 6
    243 1
    256 3
    259 2
    266 3
    271 4
    274 9
    277 16
    277 24
    277 31
    277 41
    277 48
    278 57
    278 62
    278 66
    24
    190 73
    191 64
    193 51
    194 39
    191 25
    189 17
    185 7
    184 5
    177 4
    169 4
    166 4
    159 5
    159 6
    162 19
    163 25
    165 32
    165 39
    165 47
    165 57
    162 65
    161 70
    159 75
    158 78
    157 80
    15
    96 157
    93 163
    88 176
    82 184
    78 193
    75 201
    72 212
    72 224
    72 238
    73 254
    75 267
    78 277
    82 286
    89 298
    89 300
    9
    33 428
    33 428
    33 427
    35 426
    36 425
    30 427
    27 428
    27 428
    28 428
    16
    2 435
    5 434
    10 432
    13 431
    16 429
    19 427
    21 426
    22 425
    24 424
    26 423
    27 423
    30 422
    33 422
    34 421
    36 420
    36 419
    77
    32 436
    55 423
    67 415
    75 409
    86 401
    92 395
    98 389
    105 378
    107 372
    111 362
    112 355
    116 345
    119 338
    121 328
    124 317
    125 312
    125 304
    126 294
    125 288
    124 280
    125 277
    125 258
    124 255
    125 241
    128 235
    135 225
    141 218
    147 211
    155 208
    166 205
    178 203
    194 202
    209 203
    219 204
    232 205
    249 206
    259 207
    284 205
    300 198
    317 189
    333 182
    345 170
    362 153
    392 135
    430 118
    450 104
    477 91
    509 75
    539 65
    567 61
    599 60
    625 59
    635 58
    632 54
    616 51
    602 46
    593 46
    580 45
    565 41
    546 38
    526 36
    502 42
    487 48
    468 53
    452 57
    434 63
    414 71
    397 77
    378 82
    366 86
    352 90
    338 92
    328 91
    319 88
    307 86
    306 85
    301 85
    14
    318 106
    333 107
    346 109
    359 111
    369 104
    391 100
    411 95
    431 87
    445 81
    458 71
    473 63
    491 59
    497 57
    499 56
    7
    244 109
    235 104
    221 100
    208 96
    199 97
    190 98
    190 98
    8
    160 116
    165 119
    171 122
    172 127
    170 135
    168 144
    170 149
    174 149
    4
    169 118
    174 120
    179 124
    178 126
    8
    293 132
    294 125
    297 115
    291 94
    287 90
    290 84
    297 79
    297 79
    6
    144 97
    143 83
    144 72
    141 58
    136 52
    134 49

  • 相关阅读:
    设计模式—— 十 :模板方法模式
    设计模式—— 九 :抽象工厂模式
    StringUtils常用方法
    设计模式—— 八 :工厂方法模式
    Navicat查看并导出ER图
    设计模式—— 七 :单例模式
    设计模式—— 六:开闭原则
    设计模式—— 五:迪米特原则
    Java编码辅助工具:Mapstruct—— Java对象转换框架
    Java编码辅助工具:Lombok —— 避免重复臃肿的代码,提高效率
  • 原文地址:https://www.cnblogs.com/Alip/p/5085493.html
Copyright © 2020-2023  润新知