⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sprite.cpp

📁 小型的3D游戏引擎
💻 CPP
字号:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#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();
}

////////////////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -