/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/src/drivers/common/opengl/ogl_texture_property_quadric.cpp

*/

#include "sgx/core/core.hpp"
#include "sgx/graphics/graphics.hpp"
#include "drivers/common/opengl/opengl.hpp"

sgxOpenGLTexturePropertyQuadric::sgxOpenGLTexturePropertyQuadric()
{
	m_Quadratic = gluNewQuadric();
}

sgxOpenGLTexturePropertyQuadric::~sgxOpenGLTexturePropertyQuadric()
{
	gluDeleteQuadric(m_Quadratic);
}

tBOOL 
sgxOpenGLTexturePropertyQuadric::applyTexture(GLuint texture_id)
{
	glBindTexture(GL_TEXTURE_2D, texture_id);

	gluQuadricNormals(m_Quadratic, GLU_SMOOTH);
	gluQuadricTexture(m_Quadratic, GL_TRUE);
	gluQuadricDrawStyle(m_Quadratic, GLU_FILL); 

	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

	glEnable(GL_TEXTURE_GEN_S);
	glEnable(GL_TEXTURE_GEN_T);

	return TRUE;
}

tBOOL
sgxOpenGLTexturePropertyQuadric::drawSphere(tREAL32 radius)
{
	// TODO: TEMP: Show off some rotation on the sphere
	gluDisk(m_Quadratic, radius/2, radius, 16, 16);
	gluSphere(m_Quadratic, radius/2, 16, 16);
	return TRUE;
}
