Click here to Skip to main content
15,887,746 members
Articles / Multimedia / OpenGL

OAG Library (OpenGL) Part 2.3 - Drawing 2D Textures Using the Mouse and Programatically

Rate me:
Please Sign up or sign in to vote.
4.29/5 (6 votes)
22 Oct 2010CPOL3 min read 34.1K   1.3K   17  
This tutorial shows library code for 2D Textures and how to draw them programatically using the mouse in an MFC application.
#ifdef _MSC_VER
#include "..\..\include\oag\OAGSphere.h"
#endif

oag::OAGSphere::OAGSphere(void)
:oag::OAGQuadric(10,10)
,m_dRadius(1)
{
}

//Creates a sphere with numbers for slices and stacks
//@Param dRadius - The radius for the sphere
//@Param slices - The number of subdivisions around the z-axis (similar to lines of longitude). 
//@Param stacks - The number of subdivisions along the z-axis (similar to lines of latitude). 
oag::OAGSphere::OAGSphere(GLdouble dRadius, GLint nSlices, GLint nStacks)
:oag::OAGQuadric(nSlices, nStacks)
,m_dRadius(dRadius)
{
}

oag::OAGSphere::~OAGSphere(void)
{
}

//Operations

void oag::OAGSphere::OnDraw()
{

	::glPushMatrix();

	::glColor4ubv( m_Color.GetColor4ubv() );

	::glPolygonMode(m_PolygonFace, m_PolygonMode);

	::glTranslated( m_position.m_X, m_position.m_Y, m_position.m_Z);
	::glScalef( m_scale.m_X, m_scale.m_Y, m_scale.m_Z);
	::glRotatef( m_rotation.m_X, 1.0, 0, 0);
	::glRotatef( m_rotation.m_Y, 0, 1.0, 0);
	::glRotatef( m_rotation.m_Z, 0, 0, 1.0);

	::gluQuadricNormals(m_pQuadric, GLU_SMOOTH);

	::gluSphere( m_pQuadric, m_dRadius, m_nSlices, m_nStacks);

	::glPopMatrix();

}

void oag::OAGSphere::ReadNodeXML(CXmlNode* pNode)
{
	oag::OAGQuadric::ReadNodeXML(pNode);

	CXmlNode* pNodeSphere = pNode->GetNode("Sphere");

	if ( pNodeSphere )
	{
		CXmlNode* pNodeRadius = pNodeSphere->GetNode("Radius");
		if ( pNodeRadius )
			m_dRadius = atof( pNodeRadius->GetAttribute("value").c_str() );
		
	}
}

void oag::OAGSphere::SaveNodeXML(CXmlNode* pNode)
{
	oag::OAGQuadric::SaveNodeXML( pNode );

	CXmlNode* pNodeQuadric = pNode->GetLastChild();

	if ( pNodeQuadric )
	{
		CXmlNode* pNodeSphere = new CXmlNode("Sphere");
		pNodeQuadric->AppendChild( pNodeSphere );

		char buffer[_CVTBUFSIZE];

		CXmlNode* pNodeRadius = new CXmlNode("Radius");
		pNodeSphere->AppendChild( pNodeRadius );

		_gcvt_s(buffer, _CVTBUFSIZE, m_dRadius, 4 );  pNodeRadius->AddAttribute("value", buffer);

	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Brazil Brazil
I live in Matão, a small city in Brazil. I studied as Programmer in a College for Software Development in Database.
After finishing the College I have been working with java, c# and Computer Graphics with searches for OpenGL.

Comments and Discussions