zoukankan      html  css  js  c++  java
  • 点画填充多边形

    代码如下:

    #include <windows.h>
    //#include <GLUT/glut.h>
    #include <GL/glut.h>
    #include <math.h>
    #include <iostream>
    using namespace std;
    
    #define GL_PI 3.1415f
    
    GLubyte fire[]={
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0xc0,
        0x00,0x00,0x01,0xf0,
        0x00,0x00,0x07,0xf0,
        0x0f,0x00,0x1f,0xe0,
        0x1f,0x80,0x1f,0xc0,
        0x0f,0xc0,0x3f,0x80,
        0x07,0xe0,0x7e,0x00,
        0x03,0xf0,0xff,0x80,
        0x03,0xf5,0xff,0xe0,
        0x07,0xfd,0xff,0xf8,
        0x1f,0xfc,0xff,0xe8,
        0xff,0xe3,0xbf,0x70,
        0xde,0x80,0xb7,0x00,
        0x71,0x10,0x4a,0x80,
        0x03,0x10,0x4e,0x40,
        0x02,0x88,0x8c,0x20,
        0x05,0x05,0x04,0x40,
        0x02,0x82,0x14,0x40,
        0x02,0x40,0x10,0x80,
        0x02,0x64,0x1a,0x80,
        0x00,0x92,0x29,0x00,
        0x00,0xb0,0x48,0x00,
        0x00,0xc8,0x90,0x00,
        0x00,0x85,0x10,0x00,
        0x00,0x03,0x00,0x00,
        0x00,0x00,0x10,0x00,
    };
    
    
    void RenderScene()
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glBegin(GL_POLYGON);
            glVertex2f(-20.0f,50.0f);
            glVertex2f(20.0f,50.0f);
            glVertex2f(50.0f,20.0f);
            glVertex2f(50.0f,-20.0f);
            glVertex2f(20.0f,-50.0f);
            glVertex2f(-20.0f,-50.0f);
            glVertex2f(-50.0f,-20.0f);
            glVertex2f(-50.0f,20.0f);
        glEnd();
        glutSwapBuffers();
    
    }
    
    void ChangeSize(GLsizei w,GLsizei h)
    {
        if(h==0)
            h = 1;
    
        GLfloat aspectRatio = (GLfloat)w/(GLfloat)h;
    
        glViewport(0,0,w,h);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
    
        if(w<=h)
            glOrtho(-100,100,-100/aspectRatio,100/aspectRatio,100.0,-100.0);
        else
            glOrtho(-100*aspectRatio,100*aspectRatio,-100,100,100.0,-100.0);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
    }
    
    void SetupRC()
    {
        glClearColor(0.0f,0.0f,0.0f,1.0f);
        glColor3f(1.0f,0.0f,0.0f);
        glEnable(GL_POLYGON_STIPPLE);
        glPolygonStipple(fire);
    }
    
    
    int main(int argc, char *argv[])
    {
       glutInit(&argc,argv);
       glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
       glutInitWindowSize(800,600);
       glutCreateWindow("Simple");
    
       glutDisplayFunc(RenderScene);
       glutReshapeFunc(ChangeSize);
    
       SetupRC();
       glutMainLoop();
       return 0;
    }
    态度决定高度,细节决定成败,
  • 相关阅读:
    如何保证access_token长期有效
    微信自定义菜单的创建
    是否同一棵二叉搜索树
    Tree Traversals Again(根据前序,中序,确定后序顺序)
    List Leaves 树的层序遍历
    leetcode-优美的排列
    leetcode-下一个排列
    leetcode-二进制手表
    leetcode-组合总数III(回溯)
    leetcode-累加数(C++)
  • 原文地址:https://www.cnblogs.com/lxk2010012997/p/4199295.html
Copyright © 2011-2022 走看看