I’m having a bit of a problem with this - whilst rotating is okay and has no discernible effect on program speed, scaling is another matter : It slows down the program no end, and only seems to be able to scale in integer values (despite being sent floating-point numbers).
My display code is :
oid __GLBASIC__::__DRAWSPRITE(int id,int frame,int x,int y,DGNat angle,DGNat scale)
{
SDL_Surface *tempSurface=NULL,*rotSurface=NULL;
SDL_Texture *texture=NULL;
SDL_Rect sourcePos,destPos,pos;
int ax,ay;
if ((id>=0 && id<BOUNDS(sprites,0)) && (frame>=0 && frame<sprites(id).framesAcross*sprites(id).framesDown))
{
if (sprites(id).surface)
{
tempSurface=SDL_CreateRGBSurface(0,sprites(id).width,sprites(id).height,32,0,0,0,255);
if (tempSurface)
{
ax=(int) (frame/sprites(id).framesAcross);
ay=(int) (frame-(ax*sprites(id).framesAcross));
sourcePos.w=sprites(id).frameWidth;
sourcePos.h=sprites(id).frameHeight;
sourcePos.x=ax*sourcePos.w;
sourcePos.y=ay*sourcePos.h;
destPos.x=0;
destPos.y=0;
destPos.w=sourcePos.w;
destPos.h=sourcePos.h;
if (SDL_BlitSurface(sprites(id).surface,&sourcePos,tempSurface,&destPos)==0)
{
rotSurface=rotozoomSurface(tempSurface,angle,scale,1.0);
if (rotSurface)
{
texture=SDL_CreateTextureFromSurface(m_mainRenderer,rotSurface);
if (texture)
{
pos.x=x;
pos.y=y;
pos.w=rotSurface->w;
pos.h=rotSurface->h;
SDL_RenderCopy(m_mainRenderer,texture,NULL,&pos);
}
}
}
}
}
if (texture) SDL_DestroyTexture(texture);
if (rotSurface) SDL_FreeSurface(rotSurface);
if (tempSurface) SDL_FreeSurface(tempSurface);
}
}
And is called with :
void __GLBASIC__::ROTOZOOMSPRITE(DGNat id,DGNat x,DGNat y,DGInt angle,DGInt scale)
{
__DRAWSPRITE(id,0,x,y,angle,scale);
}
DGNat & DGInt are :
typedef int DGNat;
typedef std::string DGStr;
typedef double DGInt;