www.pudn.com > Gimcrack-v0.0051-Source.zip > sprite.cpp


#include  
#include  
#include  
#include "sprite.h" 
#include "../global.h" 
 
 
//////////////////////////////////////////////////////////////////////////////////////////// 
 
GcSprite::GcSprite(): 
width(0), 
height(0) 
{ 
	// Constructing the sprite object 
} 
 
//////////////////////////////////////////////////////////////////////////////////////////// 
 
GcSprite::~GcSprite() 
{ 
} 
 
//////////////////////////////////////////////////////////////////////////////////////////// 
 
bool GcSprite::Load(char *fileName, int sWidth, int sHeight) 
{ 
	// Save the width and height 
	width = sWidth; 
	height = sHeight; 
	 
	// Create the texture 
	if(!texture.Create(fileName)) 
	{ 
		MessageBox(NULL, "Unable to load sprite.", "ERROR", MB_OK); 
		return false; 
	} 
 
	return true; 
} 
 
//////////////////////////////////////////////////////////////////////////////////////////// 
 
void GcSprite::Draw(float x, float y) 
{ 
	glPushMatrix(); 
 
		// Move to the correct palce 
		glTranslatef(x - width / 2, y - height / 2, 0.0f); 
 
		// Set the correct texture 
		texture.Bind(); 
 
		// Draw the sprite (a textured quad) 
		glBegin(GL_QUADS); 
			glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); 
			glTexCoord2f(1.0f, 0.0f); glVertex3f((float)width, 0.0f, 0.0f); 
			glTexCoord2f(1.0f, 1.0f); glVertex3f((float)width, (float)height, 0.0f); 
			glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, (float)height, 0.0f); 
		glEnd(); 
 
	glPopMatrix(); 
} 
 
////////////////////////////////////////////////////////////////////////////////////////////