📄 sprite.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 + -