Click here to Skip to main content
15,891,905 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 "..\..\..\OpenGL\include\oag\OAGObject.h"
#include "..\..\..\OpenGL\include\oag\OAGCamera.h"
#endif

oag::OAGObject::OAGObject(void)
:oag::OAGNode()
,m_strName("")
,m_bIsSelected(false)
,m_PolygonFace(GL_FRONT_AND_BACK)
,m_PolygonMode(GL_LINE)
{
	m_scale.SetVertex(1, 1, 1);
}

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

//Operations

//Draws the objects and childs
void oag::OAGObject::Draw()
{
	OnDraw();

	if( HasChild() )
	{
		for( vector<int>::size_type i = 0; i < m_ListChilds.size(); ++i )
		{
			oag::OAGObject* childObj = (oag::OAGObject*)m_ListChilds[i];
			if( childObj )
				childObj->Draw();
		}				
	}
}

void oag::OAGObject::ReadNodeXML(CXmlNode* pNode)
{
	SetObjectName( pNode->GetAttribute("Name") );

	CXmlNode* pNodeTransform = pNode->GetNode("Transform");
	if ( pNodeTransform )
	{
		SetPosition( pNodeTransform );
		SetScale( pNodeTransform );
		SetRotation( pNodeTransform );
	}

	CXmlNode* pNodeColor = pNode->GetNode("Color");
	if( pNodeColor )
		SetColor(pNodeColor);
}

void oag::OAGObject::SaveNodeXML(CXmlNode* pNode)
{
	pNode->AddAttribute( "Name", m_strName );

	//Creating the color node
	pNode->AppendChild( CreateNodeColor() );

	CXmlNode* pNodeTransform = new CXmlNode("Transform");
	pNode->AppendChild( pNodeTransform );

	//Creating the Position
	CXmlNode* pNodeTranslation =  CreateVectorNodeAttribute( &m_position, "Translation");
	pNodeTransform->AppendChild( pNodeTranslation );

	CXmlNode* pNodeScale = CreateVectorNodeAttribute( &m_scale, "Scale");
	pNodeTransform->AppendChild( pNodeScale );

	//Creating the Rotation
	CXmlNode* pNodeRotation = CreateVectorNodeAttribute( &m_rotation, "Rotation");
	pNodeTransform->AppendChild( pNodeRotation );
}

//Operations for XML


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