1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
Csprite::Csprite() : CNode()
{
m_pTexture = NULL;
}
Csprite::Csprite(const char *pFilename): CNode()
{
m_pTexture = new CTexture(pFilename);
if (m_pTexture)
{
m_pTexture->GetSize(m_fWidth,m_fHeight);
}
}
Csprite::~Csprite()
{
}
void Csprite::Draw()
{
unsigned int colour = 0;
Vector2 tl(-m_fWidth*0.5f, -m_fHeight*0.5f); //Top left,
Vector2 tr(m_fWidth*0.5f, -m_fHeight*0.5f); //Top Right
Vector2 br(m_fWidth*0.5f, m_fHeight*0.5f); //Bottom Right
Vector2 bl(-m_fWidth*0.5f, m_fHeight*0.5f); //Bottom Right
// transform those point... the matrix should have the scale rotation and translation
tl = m_transform.TransformPoint(tl);
tr = m_transform.TransformPoint(tr);
br = m_transform.TransformPoint(br);
bl = m_transform.TransformPoint(bl);
// bind the texture
glBindTexture(GL_TEXTURE_2D, m_pTexture->GetTextureHandle());
//start working on our quads....
glBegin(GL_QUADS);
//top left
glTexCoord2f(0, 0);
glVertex2i(tl.x,tl.y);
//bottom left
glTexCoord2f(1, 0);
glVertex2i(tr.x, tr.y);
//bottom right
glTexCoord2f(1, 1);
glVertex2i(br.x, br.y);
//top right
glTexCoord2f(0, 1);
glVertex2i(bl.x, bl.y);
glEnd();
}
|