#include "stdafx.h"
#include <GL/glut.h>
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0); //设置背景颜色为亮白;
glColor3f(0.0f, 0.0f, 0.0f); //设置绘图颜色为黑白;
glPointSize(1.0); //设置点大小;
glLineWidth(2.0); //设置线宽;
glMatrixMode(GL_PROJECTION); //设置合适的矩阵;
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0); //建立一个坐标系; }
void hardwireHouse(void)
{
glClear(GL_COLOR_BUFFER_BIT); //清屏;
glBegin(GL_LINE_LOOP); //顶点首尾连续;
glVertex2i(40, 40);
glVertex2i(40, 90);
glVertex2i(70, 120);
glVertex2i(100, 90);
glVertex2i(100, 40);
glEnd();
glBegin(GL_LINE_STRIP); //顶点首尾不连续;
glVertex2i(50, 100);
glVertex2i(50, 120);
glVertex2i(60, 120);
glVertex2i(60, 110);
glEnd();
glBegin(GL_LINE_STRIP); //顶点首尾不连续;
glVertex2i(50, 40);
glVertex2i(50, 70);
glVertex2i(60, 70);
glVertex2i(60, 40);
glEnd();
glBegin(GL_LINE_LOOP); //顶点首尾连续;
glVertex2i(80, 70);
glVertex2i(80, 80);
glVertex2i(90, 80);
glVertex2i(90, 70);
glEnd();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv); //初始工具包;
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示模式;
glutInitWindowPosition(100, 100); //设置窗口在屏幕上的位置;
glutInitWindowSize(600, 600); //设置窗口大小;
glutCreateWindow("线性房子"); //打开屏幕窗口;
glutDisplayFunc(hardwireHouse); //注册重画函数;
myInit();
glutMainLoop(); //进入永久循环;
}