/***************************************************************/
//
//
//		DirectX	[ globject.cpp ]
//
//											Author	kazuki tanaka
//											Date	2017 5/17
/*---------------------------------------------------------------
■Update : 2017/5/17
			globject.cppの作成

/*---------------------------------------------------------------
	Include File
---------------------------------------------------------------*/

#include "rendereropengl.h"
#include "system_component.h"

#include "globject.h"

#include "texturegl_interface.h"

/*---------------------------------------------------------------
	Macro Difinition
---------------------------------------------------------------*/

#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p)=NULL; } }


/*---------------------------------------------------------------
	Const Number Difinition
---------------------------------------------------------------*/

#define NUM_VERTEX  ( 4 )						
#define NUM_POLYGON ( 2 )						

/*----------------------------------------------------------------
	static member variable Initialize 
----------------------------------------------------------------*/





// CGLObject Constructor
CGLObject::CGLObject( )
{

	// Menber Clear Process

}

// CGLObject Destructor
CGLObject::~CGLObject( )
{

	// Do Nothing!!

}

// CGLObject Create Instance 
CGLObject* CGLObject::Create( void )
{

	// Create Class Instance
	CGLObject* pObject;
	pObject = new CGLObject;

	return pObject;

}

// CGLObject Initialize
void CGLObject::Init( void )
{

	// Initialize Process
	index = TextureGLInterface::GLTextureLoadFromPng( "data\\car000.png" );

	pos = Vector3( 0, 0, 0 );

}

// CGLObject Uninitialize
void CGLObject::Uninit( void )
{

	// Uninitialize Process


}

// CGLObject Update
void CGLObject::Update( void )
{

	// Update Process


}

// CGLObject Draw
void CGLObject::Draw( void )
{

	// Draw Process
	// Lighting
	//glDisable( GL_LIGHTING );
	//glEnable( GL_LIGHTING );

	static unsigned int angle;

	// 2D用マトリクス
	glMatrixMode( GL_PROJECTION );
	//glPushMatrix( );
	glLoadIdentity( );
	const int SCREEN_WIDTH  = 1280;
	const int SCREEN_HEIGHT = 720;

	gluPerspective( 
		60,
		(double)SCREEN_WIDTH/SCREEN_HEIGHT,
		0.1,
		1000.0 );

	glMatrixMode( GL_MODELVIEW );
	//glPushMatrix( );
	glLoadIdentity( );

	Color diffuse( 1, 1, 1, 1 );
	Color emission( 0, 0, 0, 0 );
	float shine = 0.3f;

	// マテリアル設定
	glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, (float*)&diffuse );		// GL_AMBIENT
	glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, (float*)&emission );		// GL_EMISSION
	glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, &shine );				// GL_SHININESS


	Vector3 posEye( 0, 0, 0 );
    gluLookAt(0.0, 1.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

	/*
	glPushMatrix( );
	

	{

		//glTranslated( LENGTH, 0, 0 );
		//glRotated( 90, 0.0, 1.0, 0.0 );
		//glScalef( 0.5f, 0.5f, 0.5f );

		//glMatrixMode( GL_TEXTURE );
		//glRotated( rot, 0, 0, 1 );

		glBindTexture( GL_TEXTURE_2D, index );

		for( int index = 0; index < 4; index++ ){

			glPushMatrix( );

			const float length = 1.0f;

			glRotated( angle, 0, 1, 1 );
			glRotated( -90*index, 0, 1, 0 );
			glTranslated( 0, 0, length );

			// Render Polygon
			glBegin( GL_TRIANGLE_STRIP );

				glColor4f( 1, 1, 0, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 0, 0 );
				glVertex3f( -1, -1, 0 );

				glColor4f( 1, 1, 1, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 1, 0 );
				glVertex3f( 1, -1, 0 );

				glColor4f( 1, 0, 0, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 0, 1 );
				glVertex3f( -1, 1, 0 );

				glColor4f( 1, 0, 1, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 1, 1 );
				glVertex3f( 1, 1, 0 );

			glEnd( );

			glPopMatrix( );

			glPushMatrix( );

			glRotated( angle, 0, 1, 1 );
			glRotated( -90*index, 1, 0, 0 );
			glTranslated( 0, 0, length );


			// Render Polygon
			glBegin( GL_TRIANGLE_STRIP );

				glColor4f( 1, 1, 0, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 0, 0 );
				glVertex3f( -1, -1, 0 );

				glColor4f( 1, 1, 1, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 1, 0 );
				glVertex3f( 1, -1, 0 );

				glColor4f( 1, 0, 0, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 0, 1 );
				glVertex3f( -1, 1, 0 );

				glColor4f( 1, 0, 1, 1 );
				glNormal3f( 1, 1, 1 );
				glTexCoord2f( 1, 1 );
				glVertex3f( 1, 1, 0 );

			glEnd( );

			glPopMatrix( );


		}

	}

	glPopMatrix( );
	*/


	// ライティング有効
	glEnable( GL_LIGHTING );

	angle++;
	

}





