求助大佬帮忙看看这个程序

#include
#include
#include
#include
#include
#include

typedef long BOOL;
typedef long LONG;
typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef unsigned short WORD;

typedef struct
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BMPFILEHEADER_T;

struct BMPFILEHEADER_S
{
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
};

typedef struct
{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BMPINFOHEADER_T;

typedef struct XET
{
float x;
float dx, ymax;
XET* next;
}AET, NET;

struct point
{
float x;
float y;
};

void generateBmp(BYTE * pData, int width, int height, char * filename) //创建bmp文件
{
int size = width * height * 3;
BMPFILEHEADER_T bfh;
bfh.bfType = 0X4d42;
bfh.bfSize = size
+ sizeof(BMPFILEHEADER_T)
+ sizeof(BMPINFOHEADER_T)
;
bfh.bfReserved1 = 0;
bfh.bfReserved2 = 0;
bfh.bfOffBits = bfh.bfSize - size;

BMPINFOHEADER_T bih;
bih.biSize = sizeof(BMPINFOHEADER_T);
bih.biWidth = width;
bih.biHeight = height;
bih.biPlanes = 1;
bih.biBitCount = 24;
bih.biCompression = 0;
bih.biSizeImage = size;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;

FILE * fp = fopen(filename, "wb");
if (!fp) return;
fwrite(&bfh, 1, sizeof(BMPFILEHEADER_T), fp);
fwrite(&bih, 1, sizeof(BMPINFOHEADER_T), fp);
fwrite(pData, 1, size, fp);
fclose(fp);

}

int main()
{

struct
{
    BYTE b;
    BYTE g;
    BYTE r;
} pRGB[240][320];
memset(pRGB, 0, sizeof(pRGB));


const int POINTNUM = 6;
point polypoint[POINTNUM] = { 20,30,70,10,130,50,130,110,70,70,20,90, };

void PolyScan();
{
    int MaxY = 0;
    int i;
    for (i = 0; i < POINTNUM; i++)
    {
        if (polypoint[i].y > MaxY)
            MaxY = polypoint[i].y;
    }


    AET *pAET = new AET;
    pAET->next = NULL;

    NET *pNET[1024];
    for (i = 0; i <= MaxY; i++)
    {
        pNET[i] = new NET;
        pNET[i]->next = NULL;
    }
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1, 0, 1);
    glBegin(GL_POINTS);


    for (i = 0; i < MaxY; i++)              //扫描建立NET表
    {
        for (int j = 0; j < POINTNUM; j++)
        {
            if (polypoint[j].y == i)
            {
                if (polypoint[(j - 1 + POINTNUM) % POINTNUM].y > polypoint[j].y)
                {
                    NET *p = new NET;
                    p->x = polypoint[j].x;
                    p->ymax = polypoint[(j - 1 + POINTNUM) % POINTNUM].y;
                    p->dx = (polypoint[(j - 1 + POINTNUM) % POINTNUM].x - polypoint[j].x) / (polypoint[(j - 1 + POINTNUM) % POINTNUM].y - polypoint[j].y);
                    p->next = pNET[i]->next;
                    pNET[i]->next = p;
                }
                if (polypoint[(j + 1 + POINTNUM) % POINTNUM].y > polypoint[j].y)
                {
                    NET *p = new NET;
                    p->x = polypoint[j].x;
                    p->ymax = polypoint[(j + 1 + POINTNUM) % POINTNUM].y;
                    p->dx = (polypoint[(j + 1 + POINTNUM) % POINTNUM].x - polypoint[j].x) / (polypoint[(j + 1 + POINTNUM) % POINTNUM].y - polypoint[j].y);
                    p->next = pNET[i]->next;
                    pNET[i]->next = p;
                }
            }
        }
    }
    for (i = 0; i <= MaxY; i++)    //建立更新活性边表
    {
        NET *p = pAET->next;
        while (p)
        {
            p->x = p->x + p->dx;
            p = p->next;
        }


        AET *tq = pAET;             //AET按照X值从小到大排序
        p = pAET->next;
        tq->next = NULL;
        while (p)
        {
            while (tq->next && p->x >= tq->next->x)
                tq = tq->next;
            NET *s = p->next;
            p->next = tq->next;
            tq->next = p;
            p = s;
            tq = pAET;
        }


        AET *q = pAET;              //从AET中删除ymax == i的结点
        p = q->next;
        while (p)
        {
            if (p->ymax == i)
            {
                q->next = p->next;
                delete p;
                p = q->next;
            }
            else
            {
                q = q->next;
                p = q->next;
            }
        }


        p = pNET[i]->next;          //将NET中的新点加入AET,并用插入法按X值递增排序
        q = pAET;
        while (p)
        {
            while (q->next && p->x >= q->next->x)
                q = q->next;
            NET *s = p->next;
            p->next = q->next;
            q->next = p;
            p = s;
            q = pAET;
        }


        p = pAET->next;               //颜色填充         
        while (p && p->next)
        {
            for (float j = p->x; j <= p->next->x; j++)
            {
                glVertex2i(static_cast<int>(j), i);
            }
            p = p->next->next;
        }
    }
    glEnd();
    glFlush();
}

void init();
{
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glMatrixMode(GL_PROJECTION);
    gluOrtho2D(0, 200, 0, 200);

}

int main(int argc, char* argv);
{
    glutInit(&argc, &argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(800, 800);
    glutCreateWindow(" OpenGL ");

    init();
    glutDisplayFunc(PolyScan);
    glutMainLoop();
}

generateBmp((BYTE*)pRGB, 320, 240, "f:\\rgb.bmp");

}

c++
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!