Click here to Skip to main content
15,897,518 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.
#include "XmlWriterDocument.h"
#include "XmlNode.h"
#include "XmlAttribute.h"

#if defined(LIBXML_WRITER_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)
#define MY_ENCODING "ISO-8859-1"
#endif

CXmlWriterDocument::CXmlWriterDocument(void)
{
}

CXmlWriterDocument::~CXmlWriterDocument(void)
{
}

//Operations

int CXmlWriterDocument::WriteNode(CXmlNode* pNode, xmlTextWriterPtr writer)
{
	std::string text = pNode->GetNodeName();
	int rc = xmlTextWriterStartElement(writer, BAD_CAST (xmlChar*)text.c_str());
	if ( rc < 0)
		return rc;

	for( vector<int>::size_type i = 0; i < pNode->m_ListAtts.size(); ++i )
	{	
		CXmlAttribute* pAttr = pNode->m_ListAtts[i];

		std::string name =  pAttr->GetName();
		std::string value = pAttr->GetValue();


	   /* Add an attribute with name "version" and value "1.0" to ORDER. */
		rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (xmlChar*)name.c_str(),
										 BAD_CAST (xmlChar*)value.c_str() );
		if (rc < 0)
		{
			return rc;
			break;
		}

	}

	for( vector<int>::size_type i = 0; i < pNode->m_ListChilds.size(); ++i )
	{	
		rc =   this->WriteNode( pNode->m_ListChilds[i], writer );
		if ( rc < 0 )
		{
			return rc;
			break;
		}
	}

	rc = xmlTextWriterEndElement(writer);
	if ( rc < 0 )
		return rc; 

	return 0;
}

void CXmlWriterDocument::WriteFile(std::string strFileName, CXmlNode* pRoot)
{
#if defined(LIBXML_WRITER_ENABLED) && defined(LIBXML_OUTPUT_ENABLED)

    int rc;
    xmlTextWriterPtr writer;
    xmlChar *tmp;
    xmlDocPtr doc;

	if ( pRoot == NULL )
		return;

    /* Create a new XmlWriter for DOM, with no compression. */
    writer = xmlNewTextWriterDoc(&doc, 0);


    /* Start the document with the xml default for the version,
     * encoding ISO 8859-1 and the default for the standalone
     * declaration. */
    rc = xmlTextWriterStartDocument(writer, NULL, MY_ENCODING, NULL);
    if (rc < 0) {
        printf("testXmlwriterDoc: Error at xmlTextWriterStartDocument\n");
        return;
    }

	this->WriteNode(pRoot, writer);

    xmlFreeTextWriter(writer);

	xmlSaveFileEnc(strFileName.c_str(), doc, MY_ENCODING);

    xmlFreeDoc(doc);

    /*
     * Cleanup function for the XML library.
     */
    xmlCleanupParser();
    /*
     * this is to debug memory for regression tests
     */
    xmlMemoryDump();

#endif

}

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