#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();
#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();
}