The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
rotozoomSurface
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
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 :

Code:
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 :

Code:
void    __GLBASIC__::ROTOZOOMSPRITE(DGNat id,DGNat x,DGNat y,DGInt angle,DGInt scale)
{
    __DRAWSPRITE(id,0,x,y,angle,scale);
}


DGNat & DGInt are :

Code:
typedef         int                DGNat;
typedef         std::string         DGStr;
typedef         double             DGInt;
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Silly me - should have been DGInt angle and DGInt scale - using both also speeds things up.