多次调用parameterizedHouse()绘制村庄 源代码

#include<windows.h>
#include <gl/glut.h>

struct GLintPoint{
    GLint x , y;
};

struct GLWidthHeight{
    GLint width,height;
};
const GLint screenWidth = 500;
const GLint screenHeight = 250;


void myDisplay(void);
void myInit(void);
void parameterizedHouse(GLintPoint peak, GLint width, GLint height);

int main(int argc, char ** argv){
    glutInit(&argc,argv);
    //GLUT_RGB 不是GLU_RGB
    /************************************************************************/
    /* GLUT: Fatal Error in ....Test001.c.exe: pixel format with necessary capabilities not found.                                                                     */
    /************************************************************************/
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    glutInitWindowSize(screenWidth,screenHeight);
    glutInitWindowPosition(100,150);
    //没有这一句会停止工作
    glutCreateWindow("Villages");


    glutDisplayFunc(myDisplay);
    myInit();
    glutMainLoop();
    return 0;
}

void myDisplay(void){
    glClear(GL_COLOR_BUFFER_BIT);
    GLintPoint vertex[9] = {{100,200},{190,200},{310,210},{400,180},{70,120},{150,110},{220,70},{320,110},{420,50}};
    GLWidthHeight wh[9] = {{50,60},{70,60},{50,80},{40,50},{60,80},{40,100},{-60,60},{60,40},{-60,-60}};

    for ( int i = 0; i< 9; ++i)
    {
        parameterizedHouse(vertex[i],wh[i].width,wh[i].height);
    }
    

}

void myInit(void){
    glClearColor(1.0,1.0,1.0,0.0);
    glColor3f(0.0f,0.0f,0.0f);
    glPointSize(2.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble)screenHeight);

}

void parameterizedHouse(GLintPoint peak, GLint width, GLint height){
    //逆时针绘制房子轮廓 坐下,右下 ,右上, 左上
    glBegin(GL_LINE_LOOP);    
    glVertex2i(peak.x-width/2,peak.y-height);
    glVertex2i(peak.x+width/2,peak.y-height);
    glVertex2i(peak.x+width/2,peak.y-3*height/8);
    glVertex2i(peak.x,peak.y);
    glVertex2i(peak.x-width/2,peak.y-3*height/8);
    glEnd();

    //烟囱
    glBegin(GL_LINE_LOOP);
        glVertex2i(peak.x-2*width/6, peak.y-2*height/8);
        glVertex2i(peak.x-1*width/6, peak.y-height/8);
        glVertex2i(peak.x-1*width/6, peak.y);
        glVertex2i(peak.x-2*width/6, peak.y);
    glEnd();

    //门
    glBegin(GL_LINE_LOOP);
        glVertex2i(peak.x-2*width/6, peak.y-height);
        glVertex2i(peak.x-1*width/6, peak.y-height);
        glVertex2i(peak.x-1*width/6, peak.y-5*height/8);
        glVertex2i(peak.x-2*width/6, peak.y-5*height/8);
    glEnd();

    //窗户
    glBegin(GL_LINE_LOOP);
        glVertex2i(peak.x+1*width/6, peak.y-5*height/8);
        glVertex2i(peak.x+2*width/6, peak.y-5*height/8);
        glVertex2i(peak.x+2*width/6, peak.y-4*height/8);
        glVertex2i(peak.x+1*width/6, peak.y-4*height/8);
    glEnd();


    glFlush();

}




  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值