Click here to Skip to main content
15,885,871 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.
#pragma once

#include "..\..\include\WindowsViewer\WinGraphicContext.h"
#include "..\..\include\SceneMapping\OAGScene.h"
#include "..\..\..\Common\include\OAGVector3d.h"
#include "..\..\..\Common\include\OAGMatrix4x4.h"
#include "..\..\include\oag\OAGCamera.h"

namespace oag
{
	class WinRenderer
	{
	public:
		WinRenderer(void);
		WinRenderer(oag::WinGraphicContext*  Win32GC, bool b3DMode = false );
		~WinRenderer(void);

	//Attributes
	protected:
		std::vector<oag::OAGSceneObject*> m_listScene; 
						
		oag::WinGraphicContext*		m_prglWinGC;
		bool						m_bIs3dMode;
		oag::OAGVector3f			m_VecTranslation;
		oag::OAGVector3f			m_VecScale;
		oag::OAGVector3f			m_VecRotation;
		oag::OAGColor				m_BackGroundColor;

	public:
		oag::OAGCamera				m_Camera;

	//Operations
	public:
		void DeleteAllScenes();
		bool Is3DMode()							{ return m_bIs3dMode; };
		void GetMatrices(GLdouble *gldModelview, GLdouble *gldProjection);
		void GetOGLPos(const int nXScreenCoordinate, const int nYScreenCoordinate, oag::OAGVector3d* ptOut);
		void GetTranslation(oag::OAGVector3f* vec)	{ vec->SetVertex(m_VecTranslation); };
		void GetRotation(oag::OAGVector3f* vec)	{ vec->SetVertex(m_VecRotation); };
		void GetScale(oag::OAGVector3f* vec)		{ vec->SetVertex(m_VecScale); };
		
		void SetScene(oag::OAGSceneObject* pScene)
		{ 
			m_listScene.resize(0);
			m_listScene.push_back(pScene);
		}

		void AddScene(oag::OAGSceneObject* pScene)
		{ 
			m_listScene.push_back(pScene);
		}

		void RemoveAllScenes()
		{
			m_listScene.resize(0);
		}
		
		void ScreenToWorld(oag::OAGVector3f ptIn[], oag::OAGVector3d* ptOut, int count);
		void ScreenToWorld(const int nXScreenCoordinate, const int nYScreenCoordinate, double& fXWorldCoordinate, double& fYWorldCoordinate);
		void RenderScene();
		void ResetTransform();
		void SetBackGroundColor(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255){ m_BackGroundColor.SetColor(red, green, blue, alpha); }
		void SetTranslation(float x, float y, float z){ m_VecTranslation.SetVertex(x, y, z);  }
		void SetScale(float x, float y, float z) { m_VecScale.SetVertex(x, y, z);  }
		void SetRotation(float x, float y, float z) { m_VecRotation.SetVertex(x, y, z);  }

	};

};

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