Using SpriteManager2d, but one pixel less or more.

gxsheng

02-03-2009 05:36:08

I use SpriteManager2d to implement my 2d engine.Following the instruction :
http://www.ogre3d.org/wiki/index.php/SpriteManager2d

The texture is 32*32,but when display on the screen,the size is not exactly 32*32,but 31*32 or 33*31.So the texture is a little stretched or compressed.When display text , the effect is very bad.

I calculate the primitive [a rectangle] position like this:

1.Get window size.(I use MFC framework.) [wndSize]
2.Get texture position and size. [texPos] [texSize]
3.Calculate relative position and size of the rectangle , as:

relX = texSize.x / (float)wndSize.x ;
relY = texSize.y / (float)wndSize.y ;

posX = texPos.x / (float)wndSize.x ;
posY = texPos.y / (float)wndSize.y ;

4. call function :
void Ogre2dManager::spriteBltFull(
std::string textureName,
double x1, double y1, double x2, double y2,
double tx1, double ty1, double tx2, double ty2)
{
Ogre::TexturePtr tp;
Ogre2dSprite spr;

spr.x1=x1;
spr.y1=y1;
spr.x2=x2;
spr.y2=y2;

spr.tx1=tx1;
spr.ty1=ty1;
spr.tx2=tx2;
spr.ty2=ty2;

tp=Ogre::TextureManager::getSingleton().getByName(textureName);
spr.texHandle=tp->getHandle();

sprites.push_back(spr);
}

kungfoomasta

02-03-2009 07:55:12

This is not related to QuickGUI at all, please post your question here: http://www.ogre3d.org/forums/viewtopic.php?t=24627