Click here to Skip to main content
15,881,709 members
Articles / Desktop Programming / MFC

True OpenGL Zooming

Rate me:
Please Sign up or sign in to vote.
4.60/5 (17 votes)
11 Feb 2002 297.1K   9.9K   66  
True zooming on a perspective view...
//********************************************
// Texture.h
//********************************************
// class CTexture
//********************************************
// This object stores a bitmap image used as
// an OpenGL texture.
// Files are stored as .bmp format. 
// Depth are currently 24 or 32 bits,
// Modes are : RGB, RGBA (alpha layer).
//********************************************
// pierre.alliez@cnet.francetelecom.fr
// Created : 17/12/97
// Modified : 18/02/98
//********************************************

#ifndef _TEXTURE_
#define _TEXTURE_

class CTexture : public CObject
{

// Members datas
private :

	unsigned char *m_pData;    // datas
	unsigned int   m_Width;    // width (pixels)
	unsigned int   m_Height;   // height (pixels)
	unsigned int   m_Depth;    // bits per pixel 
	CString        m_FileName; // texture image file name

	BITMAPINFOHEADER m_Header;      // image header (display on device context)
	unsigned int     m_WidthByte32; // width (in bytes, and 32 bits aligned)

public :

	// Construction / destruction
	CTexture();
	virtual ~CTexture();

	// File reading
	int ReadFile(char *filename,unsigned int width=-1,unsigned int height=-1,unsigned int depth=-1);
	int ReadFileBMP(char *filename);
	int ReadFileRAW(char *filename,unsigned int width,unsigned int height,unsigned int depth);
	
	// File saving
	int SaveFile(char *filename);
	int SaveFileBMP(char *filename);
	int SaveFileRAW(char *filename);
   int ReadFromResource(const WORD ResourceId,LPCTSTR lpszSection);

	// Datas (explicit inline functions)
	unsigned char *GetData(void) { return m_pData; }
	unsigned int GetWidth(void)  { return m_Width; }
	unsigned int GetHeight(void) { return m_Height;}
	unsigned int GetDepth(void)  { return m_Depth; }
	CString GetFileName(void)    { return m_FileName; }

	// Misc
	int IsValid();
	int SameSize(CTexture *pTexture);
	int BGRtoRGB(void);
	int HigherPowerOfTwo(int value);
	int LowerPowerOfTwo(int value);

	// Updating
	void UpdateWidthByte32();
	void UpdateHeader();
	unsigned int WidthByte32(unsigned int width,unsigned int depth);

	// Alpha
	int HasAlpha() { return (m_Depth == 32); }
	int AddAlphaLayer(unsigned char alpha);
	int SetAlphaLayer(unsigned char alpha);
	int PutAlpha(CTexture *pTexture);	// Put an alpha layer from grey scale

	// DuplicateMirror
	int DuplicateMirror(int left=0,int top=0,int right=-1,int bottom=-1);
	int DuplicateRepeatWidth(int left=0,int top=0,int right=-1,int bottom=-1);
	int Extract(int left=0,int top=0,int right=-1,int bottom=-1);

	// Display
	int Draw(CDC *pDC,int xOffset=0,int yOffset=0, int width=-1, int height=-1);

	// Buffer
	int ReadBuffer(unsigned char *buffer, int width, int height, int depth);
	int Grey(unsigned int x,unsigned int y);

private :

	// Memory
	int Alloc(unsigned int width,unsigned int height,unsigned int depth);
	void Free(void);
   bool AllocImageData(unsigned int sizeData);

};

#endif // _TEXTURE_

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions