Click here to Skip to main content
15,886,110 members
Articles / Desktop Programming / MFC

OAG Library (OpenGL) Part 2.1 - Drawing Objects 2D using the Mouse and Programatically

Rate me:
Please Sign up or sign in to vote.
4.42/5 (11 votes)
13 Aug 2011CPOL3 min read 64.3K   45  
This tutorial shows Library Code for Geometries 2D how to draw them programatically and how draw to objects using the mouse in an application MFC.
#include "stdafx.h"
#include "RasterImageRectTool.h"
#include <OAGPrimitives.h>
#include <OAGRectangleMapping.h>

CRasterImageRectTool::CRasterImageRectTool(void)
{
}

CRasterImageRectTool::~CRasterImageRectTool(void)
{
}

//Operations

//Virtual

void CRasterImageRectTool::AddAllVerticesToScene()
{
	m_pWinGraphicContext->MakeCurrent();
	
	oag::OAGTexture* t1 =  m_pScene->GetTextureMappingTable()->GetTexture("Image1");
	if ( t1 )
	{
		//Clear filters and wraps set for the texture
		t1->ClearFiltersAndWraps();

		std::vector<OAG_TEXTURE_FILTER> filterList;

		switch( m_textureRenderMode)
		{
		case NORMAL:
			{
				//Filters
				filterList.push_back( MAG_FILTER_LINEAR);
				filterList.push_back( MIN_FILTER_LINEAR);
			}
			break;
		case REAPEATING:
			{
				//Filters
				filterList.push_back( MAG_FILTER_LINEAR);
				filterList.push_back( MIN_FILTER_LINEAR);
				
				//Reapeating
				std::vector<OAG_TEXTURE_WRAP> wrapList;
				wrapList.push_back( WRAP_S_REPEAT);
				wrapList.push_back( WRAP_T_REPEAT);
				t1->SetTextureWrap( wrapList );
				t1->SetWrapValue( 6 );//Value for texture reapeating
					
				t1->SetTextureMode( GL_MODULATE );
			}
			break;
		case CLAMPING:
			{
				//Filters
				filterList.push_back( MAG_FILTER_LINEAR);
				filterList.push_back( MIN_FILTER_LINEAR);
				
				//Clamping
				std::vector<OAG_TEXTURE_WRAP> wrapList;
				wrapList.push_back( WRAP_S_CLAMP);
				wrapList.push_back( WRAP_T_CLAMP);
				t1->SetTextureWrap( wrapList );
				t1->SetWrapValue( 4 ); //Value for texture clamping

				t1->SetTextureMode( GL_MODULATE );
			}
			break;
		}

		t1->SetTextureFilter( filterList );
		t1->SetTextureHeight(256);
		t1->SetTextureWidth(256);
		t1->BuildTexture();
	}

	oag::OAGRectangleMapping* tex = new oag::OAGRectangleMapping(t1);
	oag::OAGVector3f vec1 = m_arrVector[0];

	oag::Matrix4x4 mt;
	mt.SetTranslation(vec1.m_X, vec1.m_Y, vec1.m_Z);

	tex->SetTransform( mt );

	m_pScene->AddObject( tex );

	m_pWinGraphicContext->DeleteCurrent();

}

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