//  @ Project : hello eagl ++
//  @ File Name : helloeagl.cpp
//  @ Date : 2008-4-23
//  @ Author : kongfu.yang
//  @ Company : http://www.play3d.net
//  @ Copyright : 2008-4, Example source license. 
//        By keep this header comment, 
//        you may use this source file in your project for non-commercial or commercial purpose.

#include "eglSetup.h"
#include "callbacks.h"
#include "IO.h"
#include <string.h>
#include "helloMesh.h"

class glModelApp : public glApp
{
private:
  GLfixed g_rx,g_ry,g_rz;

  void init(void)
  {
  }

  void drawHello()
  {		
	glEnableClientState( GL_VERTEX_ARRAY );
	glVertexPointer( 2, GL_FIXED, 0, helloVertex ); // 2 means (x,y) for one vertex, coord is in float number, stride is 0

	glEnableClientState( GL_COLOR_ARRAY );
	glColorPointer( 4, GL_FIXED, 0,  helloColor); // 4 means (R,G,B, A) for color of one vertex, color is in float number, stride is 0

	glDrawArrays(GL_TRIANGLES, 0, sizeof(helloVertex)/sizeof(GLfixed)/2 );
 }

 void rendering(void)
 {
	if ( 0==makeCurrent() )
	{
	  glEnable(GL_DEPTH_TEST);
	  glDepthFunc(GL_LEQUAL);
	
		glClearColorx(Float2Fixed(0.5f), 0, 0, Float2Fixed(1.0f));
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
		//glEnable(GL_LIGHTING);
		//glEnable(GL_LIGHT0);

		glPushMatrix();
		glScalex( Float2Fixed(0.3f),Float2Fixed(1.0f),Float2Fixed(1.0f) );
		glTranslatex( Float2Fixed(-1.0f), 0, Float2Fixed(-1.0f) );

		glRotatex( g_rx, Float2Fixed(1.0f), 0, 0 );
		glRotatex( g_ry, 0, Float2Fixed(1.0f), 0 );
		glRotatex( g_rz, 0, 0, Float2Fixed(1.0f) );

		// draw here
		drawHello();

		glPopMatrix();
		swapBuffers();
	}
 }
 
void accelerating(float x, float y, float z)
{
   g_rx = Float2Fixed(x*180) ; g_ry = Float2Fixed(y*180); g_rz = Float2Fixed(z*180);
   
   rendering();
} 

};

static glModelApp  g_app;

glApp * getApp(void) { return &g_app; }
