
/**********************************************

Easy Flight Simulator !!!!!!!!!!


20021608 정동진
20031436 김현우
20062525 임윤정
20062405 박민희



*************************************************/

#pragma comment(lib, "glaux")
#include <gl\glut.h>
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h> 
#include <gl\glaux.h>
#include <math.h> 

#define GL_PI 3.14f

GLint sec = 0;             //프로펠라 회전 변수
GLint sec2 = 0;            //헬리콥터전체 회전 변수

static GLfloat xRot = 0.0f;//방향키값에 따른 변화 
static GLfloat yRot = 0.0f;//방향키값에 따른 변화

static GLuint texName[6];  //텍스처 변수

HPALETTE hPalette = NULL;
static HINSTANCE hInstance;

LRESULT CALLBACK MyWndProc(HWND, UINT, WPARAM, LPARAM);

void Renderpropella();//프로펠러
void Renderobject();  //헬리콥터 모체
void Renderobject1(); //그림자 헬리콥터 몸체
void Sky();           //하늘평면
void Ground();        //땅평면

void ChangeSize(GLsizei w, GLsizei h)
{
	GLfloat nRange = 1000.0f;

	if(h == 0)
	h = 1;

	glViewport(0, 0, w, h);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if (w <= h)
		glOrtho(-nRange, nRange, -nRange*h/w, nRange*h/w,-nRange,nRange);
	else
		glOrtho(-nRange*w/h, nRange*w/h,-nRange,nRange,-nRange,nRange);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}
void SetupLight()
{	
	GLfloat ambientLight0[] = {0.f,0.f,0.f};
	GLfloat diffuseLight0[] = {0.f,0.f,0.f};
	GLfloat specularLight0[] = {0.f,0.f,0.0f};
	GLfloat ambientLight1[] = {0.5f,0.5f,0.5f};
	GLfloat diffuseLight1[] = {0.5f,0.5f,0.5f};
	GLfloat specularLight1[] = {0.0f,0.0f,0.0f};
	GLfloat specref[] = {1.0f, 1.0f, 1.0f, 1.0f};

	glEnable(GL_LIGHTING);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
	glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
	glEnable(GL_LIGHT0);

	glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight1);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight1);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight1);
	glEnable(GL_LIGHT1);

	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
	glMateriali(GL_FRONT, GL_SHININESS, 128);
	glMaterialf(GL_FRONT, GL_EMISSION, 100.0f);
}

void fixTexSize(AUX_RGBImageRec * m_pRGBImage) // 텍스처가 2의 n승이 아닐때 2의 n승으로 만들어주는 함수
{
	double xPow2, yPow2;
	int ixPow2, iyPow2;
	int xSize2, ySize2;
	BYTE* pData;
	GLint glMaxTexDim;
	
	glGetIntegerv( GL_MAX_TEXTURE_SIZE, &glMaxTexDim );
	glMaxTexDim = min(256, glMaxTexDim);
	if (m_pRGBImage->sizeX <= glMaxTexDim)
		xPow2 = log((double)m_pRGBImage->sizeX) / log((double)2.0);
	else
		xPow2 = log((double)glMaxTexDim) / log((double)2.0);
	if (m_pRGBImage->sizeY <= glMaxTexDim)
		yPow2 = log((double)m_pRGBImage->sizeY) / log((double)2.0);
	else
		yPow2 = log((double)glMaxTexDim) / log((double)2.0);
	ixPow2 = (int)xPow2;
	iyPow2 = (int)yPow2;
	if (xPow2 != (double)ixPow2)
		ixPow2++;
	if (yPow2 != (double)iyPow2)
		iyPow2++;
	xSize2 = 1 << ixPow2;
	ySize2 = 1 << iyPow2;
	if ( xSize2 != m_pRGBImage->sizeX || ySize2 != m_pRGBImage->sizeY )
	{
		pData = (BYTE*)LocalAlloc( LMEM_FIXED,
			xSize2 * ySize2 * 3 * sizeof(BYTE) );
		gluScaleImage(GL_RGB, m_pRGBImage->sizeX, m_pRGBImage->sizeY,
			GL_UNSIGNED_BYTE, m_pRGBImage->data,
			xSize2, ySize2, GL_UNSIGNED_BYTE,
			pData);
		LocalFree(m_pRGBImage->data);
		
		m_pRGBImage->sizeX = xSize2;
		m_pRGBImage->sizeY = ySize2;
		m_pRGBImage->data = pData;
	}
}
void loadTexImage() // BMP파일이미지를 로드해 Texture에 지정하는 함수
{
	GLfloat xequ[] = {1.0f, 0.0f, 0.0f, 0.0f};
	GLfloat yequ[] = {0.0f, 1.0f, 0.0f, 0.0f};
	AUX_RGBImageRec * m_pRGBImage;
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glGenTextures(6, texName);
	
	m_pRGBImage = auxDIBImageLoad("born.bmp"); //본체텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);
	
	m_pRGBImage = auxDIBImageLoad("window.bmp");  //창문텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[1]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);

	m_pRGBImage = auxDIBImageLoad("korea.bmp"); //본체옆 태극기 텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[2]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);

	m_pRGBImage = auxDIBImageLoad("black.bmp"); //프로펠러 텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[3]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);

	m_pRGBImage = auxDIBImageLoad("sky.bmp");  //하늘 텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[4]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);

	m_pRGBImage = auxDIBImageLoad("ground.bmp"); //땅 텍스쳐
	glBindTexture(GL_TEXTURE_2D, texName[5]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	fixTexSize(m_pRGBImage);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_pRGBImage->sizeX,
		m_pRGBImage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
		m_pRGBImage->data);
	
}
	
void SetupRC()
{
	glClearColor(1.0f, 1.0f, 1.0f, 1.0f );
	glShadeModel(GL_SMOOTH);
	glColor3ub(198, 198, 198);
	glFrontFace(GL_CW);
	loadTexImage();
	SetupLight();
}

void IdleFunction()
{
	sec += 30;
	sec2 -= 3;
}
	
void Calc_shadowMatrix(GLfloat light_pos[4],GLfloat shad_plane[3][3],GLfloat shad_matrix[4][4])
{
	
	GLfloat tmp, plane_coeff[4];
	GLfloat vect_a[3], vect_b[3];
	GLint i;
	for (i = 0; i < 3; i++)
	{
		//조명을 원점에 가져다 두기 위한 작업
		shad_plane[i][0] -= light_pos[i];
		shad_plane[i][1] -= light_pos[i];
		shad_plane[i][2] -= light_pos[i];
	}
	
	//a,b 벡터를 구한다.
	vect_a[0] = shad_plane[0][1]-shad_plane[0][0];
	vect_a[1] = shad_plane[1][1]-shad_plane[1][0];
	vect_a[2] = shad_plane[2][1]-shad_plane[2][0];

	vect_b[0] = shad_plane[0][2]-shad_plane[0][0];
	vect_b[1] = shad_plane[1][2]-shad_plane[1][0];
	vect_b[2] = shad_plane[2][2]-shad_plane[2][0];

	//벡터를 외적한다.
	plane_coeff[0] = vect_a[2]*vect_b[1] - vect_a[1]*vect_b[2];
	plane_coeff[1] = vect_a[0]*vect_b[2] - vect_a[2]*vect_b[0];
	plane_coeff[2] = vect_a[1]*vect_b[0] - vect_a[0]*vect_b[1];
	

	//단위 행렬을 찾는다.
	tmp =(GLfloat)(sqrt(plane_coeff[0]*plane_coeff[0] +
		plane_coeff[1]*plane_coeff[1] +
		plane_coeff[2]*plane_coeff[2]));

	plane_coeff[0] /= tmp;
	plane_coeff[1] /= tmp;
	plane_coeff[2] /= tmp;

	//최종적인 coeff를 만든다.
	plane_coeff[3]= plane_coeff[0] * shad_plane[0][0] +
		plane_coeff[1] * shad_plane[1][0] +
		plane_coeff[2] * shad_plane[2][0];


	//마지막에 계산된 coeff 로 d값을 삼는다.
	shad_matrix[0][0] = plane_coeff[3];
	shad_matrix[1][1] = plane_coeff[3];
	shad_matrix[2][2] = plane_coeff[3];

	//a,b,c 값을 삼는다.
	shad_matrix[0][3] = plane_coeff[0];
	shad_matrix[1][3] = plane_coeff[1];
	shad_matrix[2][3] = plane_coeff[2];
}
void RenderScene(void)
{
	
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glPolygonMode(GL_BACK,GL_LINE);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);
	glClearColor(1.0f,1.0f,1.0f,1.0f);
		
	SetupLight();
	
	GLfloat light0pos[] = { 8000.0f, 8000.0f, 0.0f, 0.0f};       //라이트0 위치설정
	GLfloat light1pos[] = {-8000.0f, 8000.0f, 0.0f, 0.0f};       //라이트1 위치설정
	
	//조명 및 물체가 투영될 평면
	GLfloat shad_plane[3][3]={{1, 0, 0}, {0, 0, 0}, {0, 0, 1}};

	//그림자 행렬
	GLfloat shad_matrix[4][4] = {{0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}};

	glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
	glLightfv(GL_LIGHT1, GL_POSITION, light1pos);
	

	//그림자 행렬을 구한다.
	Calc_shadowMatrix(light0pos, shad_plane, shad_matrix);

	glPushMatrix();																		//push1
		glRotatef(20.0f, 1.0f, 0.0f, 0.0f);    //잘보이기 위해서 틀어줌		
		
		//헬기
		glPushMatrix();																	//push2
			glRotatef(xRot, 1.0f, 0.0f, 0.0f); //방향키에의해 회전하기 위해서
			glRotatef(yRot, 0.0f, 1.0f, 0.0f);
			Sky();
			Ground();					
			
			glPushMatrix();																//push3
				Renderobject();
				//헬기에 프로펠러 붙임
				glTranslatef(0.0f,-60.0f,0.0f); 
				glRotatef((float)365.0 * sec / (float)365.0, 0.0f, 1.0f, 0.0f);
				Renderpropella();
			glPopMatrix();																//pop3

			glPushAttrib(GL_LIGHTING_BIT); //빛 속성 저장

			//빛을 끄는 이유는
			//빛의 색깔 + 물체의 속성의 색이
			//투영될 면에 적용 안되게 하기 위해서이다
			glDisable(GL_LIGHTING);

		
			//헬기그림자
			glPushMatrix();																//push4
				glTranslatef(light0pos[0]-300, light0pos[1]-600, light0pos[2]);
				//이미 저장된 행렬과 shad_matrix와의 곱
				glMultMatrixf((GLfloat*) shad_matrix);
				glTranslatef(-light0pos[0], -light0pos[1], -light0pos[2]);				
				glPushMatrix();															//push5
					glColor3f(0.2f, 0.2f, 0.2f);
					Renderobject1();
					glTranslatef(0.0f,-60.0f,0.0f);
					glRotatef((float)360.0 * sec / (float)365.0, 0.0f, 1.0f, 0.0f);
					Renderpropella();
				glPopMatrix();															//pop5					
			glPopMatrix();																//pop4

			glPushMatrix();																//push4
				glTranslatef(light1pos[0]+300, light1pos[1]-600, light1pos[2]);
				//이미 저장된 행렬과 shad_matrix와의 곱
				glMultMatrixf((GLfloat*) shad_matrix);
				glTranslatef(-light1pos[0], -light1pos[1], -light1pos[2]);				
				glPushMatrix();															//push5
					glColor3f(0.2f, 0.2f, 0.2f);
					Renderobject1();
					glTranslatef(0.0f,-60.0f,0.0f);
					glRotatef((float)360.0 * sec / (float)365.0, 0.0f, 1.0f, 0.0f);
					Renderpropella();
				glPopMatrix();															//pop5					
			glPopMatrix();	

			glPopAttrib(); //빛 속성 저장된 곳으로 다시 로드
		glPopMatrix();																	//pop2
	glPopMatrix();																		//pop1
	glFlush();
}
void Renderpropella()
{		
	glBindTexture(GL_TEXTURE_2D, texName[3]);
	glBegin(GL_QUADS); //프로펠러1
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f,60.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-1.0f,60.0f,0.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-5.0f,60.0f,-255.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(5.0f,60.0f,-255.0f);
	glEnd();

	glBegin(GL_QUADS); //프로펠러2
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-1.0f,60.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(1.0f,60.0f,0.0f);	
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(5.0f,60.0f,255.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-5.0f,60.0f,255.0f);
	glEnd();

	glBegin(GL_QUADS); //프로펠러3
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-1.0f,60.0f,-1.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-1.0f,60.0f,1.0f);	
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-256.0f,60.0f,5.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-256.0f,60.0f,-5.0f);
	glEnd();
	
	glBegin(GL_QUADS); //프로펠러4
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(1.0f,60.0f,1.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(1.0f,60.0f,-1.0f);	
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(256.0f,60.0f,-5.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(256.0f,60.0f,5.0f);
	glEnd();
}
void Sky() //하늘평면 구하기
{
	glBindTexture(GL_TEXTURE_2D, texName[4]);
	glBegin(GL_QUADS); 	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-1400.0f,-601.0f,-750.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-1400.0f,1100.0f,-750.0f);		
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(1400.0f,1100.0f,-750.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(1400.0f,-601.0f,-750.0f);	
	glEnd();
}
void Ground() //땅평면구하기.
{
	glBindTexture(GL_TEXTURE_2D, texName[5]);
	glBegin(GL_QUADS); //땅
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-1400.0f,-601.0f,2100.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-1400.0f,-601.0f,-750.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(1400.0f,-601.0f,-750.0f);
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(1400.0f,-601.0f,2100.0f);
	glEnd();
}
void Renderobject() //헬기 본체
{
	glRotatef((float)360.0 * sec2 / (float)365.0, 0.0f, 1.0f, 0.0f);
	glTranslatef(450.0f,0.0f,0.0f);	
	glPushMatrix();	
	glTranslatef(0.0f,-50.0f,0.0f);		
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

	glBindTexture(GL_TEXTURE_2D, texName[0]);
	glBegin(GL_QUADS); //앞면 그리기1
	glTexCoord2f(0.0f, 0.0f);			
	glVertex3f(-24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);				
	glVertex3f(24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 1.0f);				
	glVertex3f(24.0f,30.0f,45.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,30.0f,45.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //앞면 그리기2
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,30.0f,45.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,30.0f,45.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-15.0f,60.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-15.0f,60.0f);
	glEnd();
	
	glBegin(GL_QUADS); //앞면 그리기3	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,-15.0f,60.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-15.0f,60.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-30.0f,100.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-30.0f,100.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //앞면 그리기4	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,-30.0f,100.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-30.0f,100.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,120.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,120.0f);		
	glEnd();
		
	glBegin(GL_POLYGON); //앞쪽아래오른옆
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,-15.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-45.0f,0.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,120.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(24.0f,-30.0f,100.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,-15.0f,60.0f);
	glEnd();
	
	glBegin(GL_POLYGON); //앞쪽아래왼쪽옆	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,-15.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,-15.0f,60.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,-30.0f,100.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(-24.0f,-45.0f,120.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,0.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //앞쪽아래옆	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,-45.0f,120.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-45.0f,120.0f);	
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,0.0f);
	glTexCoord2f(0.0f, 0.5f);
	glVertex3f(-24.0f,-45.0f,0.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glEnd();

	glBegin(GL_QUADS); //뒷면 위쪽 그리기	1
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,45.0f,-90.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,45.0f,-90.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,30.0f,-150.0f);
	glTexCoord2f(0.0f, 0.5f);
	glVertex3f(24.0f,30.0f,-150.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	2	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,30.0f,-150.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,30.0f,-150.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,15.0f,-150.0f);
	glTexCoord2f(0.0f, 0.5f);
	glVertex3f(24.0f,15.0f,-150.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	3	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,15.0f,-150.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,15.0f,-150.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-15.0f,-350.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-15.0f,-350.0f);
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	4	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-15.0f,-350.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-15.0f,-350.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,35.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,35.0f,-375.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	5	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,35.0f,-375.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,35.0f,-375.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,35.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,35.0f,-400.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	6	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,35.0f,-400.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,35.0f,-400.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-15.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-15.0f,-375.0f);
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	7	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-15.0f,-375.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-15.0f,-375.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-45.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-45.0f,-400.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	8	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-45.0f,-400.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-45.0f,-400.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-45.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-45.0f,-375.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	9	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-45.0f,-375.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-45.0f,-375.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-30.0f,-350.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-30.0f,-350.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //뒷면 위쪽 그리기	10	
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-30.0f,-350.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-30.0f,-350.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,-90.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,-90.0f);	
	glEnd();

	glBegin(GL_POLYGON); //오른옆면 그리기		
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,45.0f,-90.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,30.0f,-150.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,15.0f,-150.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,15.0f,-90.0f);	
	glEnd();
	
	glBegin(GL_POLYGON); //오른옆면 그리기		
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,15.0f,-90.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,15.0f,-150.0f);	
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(7.0f,-15.0f,-350.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(7.0f,-30.0f,-350.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,-90.0f);	
	glEnd();
	
	glBegin(GL_POLYGON); //꼬리오른옆면 그리기
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(7.0f,-30.0f,-350.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(7.0f,-15.0f,-350.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(7.0f,35.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,35.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-15.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-45.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(7.0f,-45.0f,-375.0f);	
	glEnd();
	
	glBegin(GL_POLYGON); //왼쪽옆면 그리기
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,45.0f,-90.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,15.0f,-90.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,15.0f,-150.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,30.0f,-150.0f);	
	glEnd();
	
	glBegin(GL_POLYGON); //왼쪽옆면 그리기		
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,15.0f,-90.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,-45.0f,-90.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-30.0f,-350.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(-7.0f,-15.0f,-350.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,15.0f,-150.0f);		
	glEnd();
	glBindTexture(GL_TEXTURE_2D, texName[0]);

	glBegin(GL_POLYGON); //꼬리왼쪽 옆면 그리기		
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-7.0f,-30.0f,-350.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-7.0f,-45.0f,-375.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-7.0f,-45.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-7.0f,-15.0f,-375.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-7.0f,35.0f,-400.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-7.0f,35.0f,-375.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-7.0f,-15.0f,-350.0f);	
	glTexCoord2f(0.0f, 1.0f);
	glEnd();
	
	glBegin(GL_TRIANGLES); //지붕
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f,60.0f,-45.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,45.0f,0.0f);
	glTexCoord2f(0.5f, 1.0f);	
	glVertex3f(-24.0f,45.0f,0.0f);		
	glEnd();
	
	glBegin(GL_TRIANGLES); //지붕
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f,60.0f,-45.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,45.0f,-90.0f);		
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(24.0f,45.0f,0.0f);	
	glEnd();
	
	glBegin(GL_TRIANGLES); //지붕
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f,60.0f,-45.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,45.0f,-90.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(24.0f,45.0f,-90.0f);			
	glEnd();
	
	glBegin(GL_TRIANGLES); //지붕
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(0.0f,60.0f,-45.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,45.0f,0.0f);
	glTexCoord2f(0.5f, 1.0f);
	glVertex3f(-24.0f,45.0f,-90.0f);		
	glEnd();
	
	
	glBindTexture(GL_TEXTURE_2D, texName[2]);
	glBegin(GL_QUADS);     //왼쪽
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,45.0f,-90.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,-90.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,0.0f);
	glEnd();	

	glBegin(GL_QUADS);     //오른쪽
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,45.0f,-90.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,0.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,-90.0f);
	glEnd();

	glBindTexture(GL_TEXTURE_2D, texName[0]);
	glBegin(GL_QUADS); //바닥
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,-45.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-45.0f,0.0f);
	glTexCoord2f(1.0f, 1.0f);
	glVertex3f(24.0f,-45.0f,-90.0f);
	glTexCoord2f(0.0f, 1.0f);
	glVertex3f(-24.0f,-45.0f,-90.0f);
	glEnd();
	

	glPushAttrib(GL_LIGHTING_BIT);
	glBindTexture(GL_TEXTURE_2D, texName[1]);
	glBegin(GL_QUADS); //윗 창문
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-22.0f,45.0f,0.0f);	
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(22.0f,45.0f,0.0f);
	glTexCoord2f(0.8f, 1.0f);
	glVertex3f(22.0f,31.0f,44.0f);
	glTexCoord2f(0.2f, 1.0f);
	glVertex3f(-22.0f,31.0f,44.0f);	
	glEnd();
	
	glBegin(GL_QUADS); //정면창문
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-22.0f,29.0f,46.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(22.0f,29.0f,46.0f);
	glTexCoord2f(0.8f, 1.0f);
	glVertex3f(22.0f,-15.0f,60.0f);
	glTexCoord2f(0.2f, 1.0f);
	glVertex3f(-22.0f,-15.0f,60.0f);
	glEnd();
	
	glBegin(GL_POLYGON); //창문
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(-24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(-24.0f,30.0f,45.0f);
	glTexCoord2f(0.8f, 1.0f);
	glVertex3f(-24.0f,-15.0f,60.0f);
	glTexCoord2f(0.2f, 1.0f);
	glVertex3f(-24.0f,-15.0f,0.0f);
	glEnd();
	
	glBegin(GL_POLYGON); //창문
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(24.0f,45.0f,0.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(24.0f,-15.0f,0.0f);
	glTexCoord2f(0.8f, 1.0f);
	glVertex3f(24.0f,-15.0f,60.0f);
	glTexCoord2f(0.2f, 1.0f);
	glVertex3f(24.0f,30.0f,45.0f);	
	glEnd();
	glPopAttrib();
	
	glBegin(GL_POLYGON); //꼬리
	glTexCoord2f(0.0f, 0.0f);
	glVertex3f(8.0f,10.0f,-368.0f);
	glTexCoord2f(1.0f, 0.0f);
	glVertex3f(8.0f,20.0f,-368.0f);		
	glTexCoord2f(0.8f, 1.0f);
	glVertex3f(8.0f,20.0f,-385.0f);
	glTexCoord2f(0.2f, 1.0f);
	glVertex3f(8.0f,10.0f,-385.0f);
	glEnd();

	glPopMatrix();	

	glTranslatef(0.0f,10.0f,-45.0f); //펠러받침
	glColor3f(1.0f,0.0f,0.0f);
	auxSolidSphere(3);
}

//그림자 헬기 몸체
void Renderobject1()
{
	glRotatef((float)360.0 * sec2 / (float)365.0, 0.0f, 1.0f, 0.0f);
	glTranslatef(450.0f,0.0f,0.0f);	
	glPushMatrix();	
		glTranslatef(0.0f,-50.0f,0.0f);	
		
		glBegin(GL_QUADS); //앞면 그리기	
		glVertex3f(-24.0f,45.0f,0.0f);
		glVertex3f(24.0f,45.0f,0.0f);
		glVertex3f(24.0f,30.0f,45.0f);
		glVertex3f(-24.0f,30.0f,45.0f);	
		glEnd();

		glBegin(GL_QUADS); //앞면 그리기	
		glVertex3f(-24.0f,30.0f,45.0f);	
		glVertex3f(24.0f,30.0f,45.0f);
		glVertex3f(24.0f,-15.0f,60.0f);
		glVertex3f(-24.0f,-15.0f,60.0f);
		glEnd();

		glBegin(GL_QUADS); //앞면 그리기	
		glVertex3f(-24.0f,-15.0f,60.0f);
		glVertex3f(24.0f,-15.0f,60.0f);
		glVertex3f(24.0f,-30.0f,100.0f);	
		glVertex3f(-24.0f,-30.0f,100.0f);	
		glEnd();

		glBegin(GL_QUADS); //앞면 그리기	
		glVertex3f(-24.0f,-30.0f,100.0f);
		glVertex3f(24.0f,-30.0f,100.0f);
		glVertex3f(24.0f,-45.0f,120.0f);
		glVertex3f(-24.0f,-45.0f,120.0f);		
		glEnd();

		glBegin(GL_POLYGON); //창문
		glVertex3f(-24.0f,45.0f,0.0f);
		glVertex3f(-24.0f,30.0f,45.0f);
		glVertex3f(-24.0f,-15.0f,60.0f);
		glVertex3f(-24.0f,-15.0f,0.0f);
		glEnd();

		glBegin(GL_POLYGON); //창문
		glVertex3f(24.0f,45.0f,0.0f);
		glVertex3f(24.0f,-15.0f,0.0f);
		glVertex3f(24.0f,-15.0f,60.0f);
		glVertex3f(24.0f,30.0f,45.0f);	
		glEnd();

		glBegin(GL_POLYGON); //앞쪽아래오른옆	
		glVertex3f(24.0f,-15.0f,0.0f);
		glVertex3f(24.0f,-45.0f,0.0f);
		glVertex3f(24.0f,-45.0f,120.0f);
		glVertex3f(24.0f,-30.0f,100.0f);
		glVertex3f(24.0f,-15.0f,60.0f);
		glEnd();

		glBegin(GL_POLYGON); //앞쪽아래왼쪽옆	
		glVertex3f(-24.0f,-15.0f,0.0f);
		glVertex3f(-24.0f,-15.0f,60.0f);
		glVertex3f(-24.0f,-30.0f,100.0f);
		glVertex3f(-24.0f,-45.0f,120.0f);
		glVertex3f(-24.0f,-45.0f,0.0f);	
		glEnd();

		glBegin(GL_QUADS); //앞쪽아래옆	
		glVertex3f(-24.0f,-45.0f,120.0f);
		glVertex3f(24.0f,-45.0f,120.0f);	
		glVertex3f(24.0f,-45.0f,0.0f);
		glVertex3f(-24.0f,-45.0f,0.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기	
		glVertex3f(24.0f,45.0f,-90.0f);
		glVertex3f(-24.0f,45.0f,-90.0f);
		glVertex3f(-24.0f,30.0f,-150.0f);
		glVertex3f(24.0f,30.0f,-150.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(24.0f,30.0f,-150.0f);
		glVertex3f(-24.0f,30.0f,-150.0f);
		glVertex3f(-24.0f,15.0f,-150.0f);
		glVertex3f(24.0f,15.0f,-150.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(24.0f,15.0f,-150.0f);
		glVertex3f(-24.0f,15.0f,-150.0f);
		glVertex3f(-7.0f,-15.0f,-350.0f);
		glVertex3f(7.0f,-15.0f,-350.0f);
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,-15.0f,-350.0f);
		glVertex3f(-7.0f,-15.0f,-350.0f);
		glVertex3f(-7.0f,35.0f,-375.0f);
		glVertex3f(7.0f,35.0f,-375.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,35.0f,-375.0f);	
		glVertex3f(-7.0f,35.0f,-375.0f);
		glVertex3f(-7.0f,35.0f,-400.0f);
		glVertex3f(7.0f,35.0f,-400.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,35.0f,-400.0f);
		glVertex3f(-7.0f,35.0f,-400.0f);
		glVertex3f(-7.0f,-15.0f,-375.0f);
		glVertex3f(7.0f,-15.0f,-375.0f);
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,-15.0f,-375.0f);
		glVertex3f(-7.0f,-15.0f,-375.0f);
		glVertex3f(-7.0f,-45.0f,-400.0f);
		glVertex3f(7.0f,-45.0f,-400.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,-45.0f,-400.0f);	
		glVertex3f(-7.0f,-45.0f,-400.0f);
		glVertex3f(-7.0f,-45.0f,-375.0f);
		glVertex3f(7.0f,-45.0f,-375.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 위쪽 그리기		
		glVertex3f(7.0f,-45.0f,-375.0f);	
		glVertex3f(-7.0f,-45.0f,-375.0f);
		glVertex3f(-7.0f,-30.0f,-350.0f);	
		glVertex3f(7.0f,-30.0f,-350.0f);	
		glEnd();

		glBegin(GL_QUADS); //뒷면 아래쪽 그리기		
		glVertex3f(7.0f,-30.0f,-350.0f);	
		glVertex3f(-7.0f,-30.0f,-350.0f);
		glVertex3f(-24.0f,-45.0f,-90.0f);	
		glVertex3f(24.0f,-45.0f,-90.0f);	
		glEnd();

		glBegin(GL_POLYGON); //오른옆면 그리기		
		glVertex3f(24.0f,45.0f,-90.0f);	
		glVertex3f(24.0f,30.0f,-150.0f);
		glVertex3f(24.0f,15.0f,-150.0f);
		glVertex3f(24.0f,15.0f,-90.0f);	
		glEnd();

		glBegin(GL_POLYGON); //오른옆면 그리기		
		glVertex3f(24.0f,15.0f,-90.0f);	
		glVertex3f(24.0f,15.0f,-150.0f);	
		glVertex3f(7.0f,-15.0f,-350.0f);
		glVertex3f(7.0f,-30.0f,-350.0f);
		glVertex3f(24.0f,-45.0f,-90.0f);	
		glEnd();

		glBegin(GL_POLYGON); //꼬리오른옆면 그리기		
		glVertex3f(7.0f,-30.0f,-350.0f);
		glVertex3f(7.0f,-15.0f,-350.0f);
		glVertex3f(7.0f,35.0f,-375.0f);
		glVertex3f(7.0f,35.0f,-400.0f);
		glVertex3f(7.0f,-15.0f,-375.0f);
		glVertex3f(7.0f,-45.0f,-400.0f);
		glVertex3f(7.0f,-45.0f,-375.0f);	
		glEnd();

		glBegin(GL_POLYGON); //왼쪽옆면 그리기		
		glVertex3f(-24.0f,45.0f,-90.0f);	
		glVertex3f(-24.0f,15.0f,-90.0f);
		glVertex3f(-24.0f,15.0f,-150.0f);
		glVertex3f(-24.0f,30.0f,-150.0f);	
		glEnd();

		glBegin(GL_POLYGON); //왼쪽옆면 그리기		
		glVertex3f(-24.0f,15.0f,-90.0f);	
		glVertex3f(-24.0f,-45.0f,-90.0f);
		glVertex3f(-7.0f,-30.0f,-350.0f);
		glVertex3f(-7.0f,-15.0f,-350.0f);
		glVertex3f(-24.0f,15.0f,-150.0f);		
		glEnd();

		glBegin(GL_POLYGON); //꼬리왼쪽 옆면 그리기		
		glVertex3f(-7.0f,-30.0f,-350.0f);
		glVertex3f(-7.0f,-45.0f,-375.0f);
		glVertex3f(-7.0f,-45.0f,-400.0f);
		glVertex3f(-7.0f,-15.0f,-375.0f);
		glVertex3f(-7.0f,35.0f,-400.0f);
		glVertex3f(-7.0f,35.0f,-375.0f);
		glVertex3f(-7.0f,-15.0f,-350.0f);	
		glEnd();

		glBegin(GL_TRIANGLES); //지붕1
		glVertex3f(0.0f,60.0f,-45.0f);
		glVertex3f(24.0f,45.0f,0.0f);
		glVertex3f(-24.0f,45.0f,0.0f);		
		glEnd();

		glBegin(GL_TRIANGLES); //지붕2
		glVertex3f(0.0f,60.0f,-45.0f);
		glVertex3f(24.0f,45.0f,-90.0f);		
		glVertex3f(24.0f,45.0f,0.0f);	
		glEnd();

		glBegin(GL_TRIANGLES); //지붕3
		glVertex3f(0.0f,60.0f,-45.0f);
		glVertex3f(-24.0f,45.0f,-90.0f);
		glVertex3f(24.0f,45.0f,-90.0f);			
		glEnd();

		glBegin(GL_TRIANGLES); //지붕4
		glVertex3f(0.0f,60.0f,-45.0f);
		glVertex3f(-24.0f,45.0f,0.0f);
		glVertex3f(-24.0f,45.0f,-90.0f);		
		glEnd();

		glBegin(GL_QUADS);//창문옆
		glVertex3f(24.0f,45.0f,0.0f);
		glVertex3f(24.0f,45.0f,-90.0f);
		glVertex3f(24.0f,-45.0f,-90.0f);
		glVertex3f(24.0f,-45.0f,0.0f);
		glEnd();	

		glBegin(GL_QUADS);//창문옆
		glVertex3f(-24.0f,45.0f,-90.0f);
		glVertex3f(-24.0f,45.0f,0.0f);
		glVertex3f(-24.0f,-45.0f,0.0f);
		glVertex3f(-24.0f,-45.0f,-90.0f);
		glEnd();

		glBegin(GL_QUADS); //창문아래바닥
		glVertex3f(-24.0f,-45.0f,0.0f);
		glVertex3f(24.0f,-45.0f,0.0f);
		glVertex3f(24.0f,-45.0f,-90.0f);
		glVertex3f(-24.0f,-45.0f,-90.0f);
		glEnd();		
		
	glPopMatrix();

	glTranslatef(0.0f,10.0f,-45.0f); //펠러받침
	auxSolidSphere(3);
}



HPALETTE GetOpenGLPalette(HDC hDC)
{
	HPALETTE hRetPal = NULL;
	PIXELFORMATDESCRIPTOR pfd;
	LOGPALETTE *pPal;
	int nPixelFormat;
	int nColors;
	int i;
	BYTE RedRange, GreenRange, BlueRange;
	
	nPixelFormat = GetPixelFormat(hDC);
	DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
	
	if(!(pfd.dwFlags & PFD_NEED_PALETTE))
		return NULL;
	
	nColors = 1 << pfd.cColorBits;
	
	pPal=(LOGPALETTE*)malloc(sizeof(LOGPALETTE)+nColors*sizeof(PALETTEENTRY));
	
	pPal->palVersion = 0x300;
	pPal->palNumEntries = nColors;
	
	RedRange = (1<<pfd.cRedBits)-1;
	GreenRange = (1<<pfd.cGreenBits)-1;
	BlueRange = (1<<pfd.cBlueBits)-1;
	
	for(i=0;i<nColors; i++)
	{
		pPal->palPalEntry[i].peRed = (i>>pfd.cRedShift)&RedRange;
		pPal->palPalEntry[i].peRed = (unsigned char)((double)pPal->palPalEntry[i].peRed*255.0/RedRange);
		
		pPal->palPalEntry[i].peGreen = (i>>pfd.cGreenShift)&GreenRange;
		pPal->palPalEntry[i].peGreen = (unsigned char)((double)pPal->palPalEntry[i].peGreen*255.0/GreenRange);
		
		pPal->palPalEntry[i].peBlue = (i>>pfd.cBlueShift)&BlueRange;
		pPal->palPalEntry[i].peBlue = (unsigned char)((double)pPal->palPalEntry[i].peBlue*255.0/BlueRange);
		
		pPal->palPalEntry[i].peFlags = (unsigned char)NULL;
	}
	
	hRetPal = CreatePalette(pPal);
	
	SelectPalette(hDC, hRetPal, FALSE);
	RealizePalette(hDC);
	
	free(pPal);
	
	return hRetPal;
}
void SetDCPixelFormat(HDC hDC)
{
	int nPixelFormat;
	static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),
			1,
			PFD_DRAW_TO_WINDOW |
			PFD_SUPPORT_OPENGL |
			PFD_DOUBLEBUFFER,
			PFD_TYPE_RGBA,
			24,
			0,0,0,0,0,0,
			0,0,
			0,0,0,0,0,
			32,
			0,
			0,
			PFD_MAIN_PLANE,
			0,
			0,0,0 
	};
	nPixelFormat = ChoosePixelFormat(hDC, &pfd);
	
	SetPixelFormat(hDC, nPixelFormat, &pfd);
	
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
	char szApplicationName[] = "flight simulator";
	HWND hwnd;
	MSG msg;
	
	WNDCLASS wc;
	
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wc.lpfnWndProc = (WNDPROC)MyWndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = szApplicationName;
	
	RegisterClass(&wc);
	
	hwnd = CreateWindow(
		szApplicationName,
		szApplicationName,
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		800,
		600,
		HWND_DESKTOP,
		NULL,
		hInstance,
		NULL
		);
	ShowWindow(hwnd, nShowCmd);
	UpdateWindow(hwnd);
	
	while(GetMessage(&msg,NULL,0,0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}

LRESULT CALLBACK MyWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HGLRC hRC; 
	static HDC hDC; 
	
	switch (message)
	{
		
		case WM_CREATE:
			hDC = GetDC(hWnd);
			SetDCPixelFormat(hDC);
			hRC = wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);
			SetupRC();
			hPalette = GetOpenGLPalette(hDC);

			SetTimer(hWnd,2,50,NULL);
			break;

		case WM_DESTROY:
			KillTimer(hWnd,101);
			wglMakeCurrent(hDC,NULL);
			wglDeleteContext(hRC);
			if(hPalette!=NULL)
				DeleteObject(hPalette);
			PostQuitMessage(0);
			break;
		
		case WM_SIZE:
			ChangeSize(LOWORD(lParam), HIWORD(lParam));
			break;

		case WM_TIMER:
			{
				IdleFunction();
				InvalidateRect(hWnd,NULL,FALSE);
			}
			break;

		case WM_PAINT:
			{
				RenderScene();
				SwapBuffers(hDC);
				ValidateRect(hWnd,NULL);
			}
			break;
	
		case WM_QUERYNEWPALETTE:
			if(hPalette)
			{
				int nRet;
				SelectPalette(hDC, hPalette, FALSE);
				nRet = RealizePalette(hDC);
				InvalidateRect(hWnd,NULL,FALSE);
				return nRet;
			}
			break;

		case WM_PALETTECHANGED:
		if((hPalette != NULL) && ((HWND)wParam != hWnd))
			{
				SelectPalette(hDC,hPalette,FALSE);
				RealizePalette(hDC);
				UpdateColors(hDC);
				return 0;
			}
			break;

		case WM_KEYDOWN:
			{
				if(wParam == VK_UP)		xRot-= 3.0f;
				if(wParam == VK_DOWN)	xRot += 3.0f;
				if(wParam == VK_LEFT)	yRot -= 3.0f;
				if(wParam == VK_RIGHT)	yRot += 3.0f;
				if(xRot > 356.0f)		xRot = 0.0f;
				if(xRot < -1.0f)		xRot = 355.0f;
				if(yRot > 356.0f)		yRot = 0.0f;
				if(yRot < -1.0f)		yRot = 355.0f;

				InvalidateRect(hWnd,NULL,FALSE);
			}
			break;

		default:
			return (DefWindowProc(hWnd, message, wParam, lParam));
		
	}
	return (0L);
}