如何将sdl纹理对象放入对象/如何传递渲染器对象?

时间:2016-03-12 03:53:07

标签: textures sdl

我是c ++和SDL2的新手。我试图制作一个包含SDL2纹理对象的对象的程序,同时将SDL_renderer对象传递给各种对象来渲染它们。我的主纹理处理程序的代码如下:

class mysurface {
    public:
    SDL_Rect pic;       // x/y where in the pic, and w/h how much of the pic.
    SDL_Rect loc;       // x/y where in the pic, and w/h how much of the pic.
    double angle = 0;
    SDL_Point center;
    std::string img = "";
    SDL_Surface *bmp;  // = SDL_LoadBMP(path.c_str());
    SDL_Texture *tex; //= SDL_CreateTextureFromSurface(ren, bmp);
    mysurface(){}
    void update(SDL_Renderer *ren, std::string image, int x, int y, int w, int h){
        this->pic.x = 0;
        this->pic.y = 0;
        this->pic.w = w;
        this->pic.h = h;

        this->loc.x = x;
        this->loc.y = y;
        this->loc.w = w;
        this->loc.h = h;

        this->center.x = (int)(this->loc.x / 2);
        this->center.y = (int)(this->loc.y / 2);

        this->img = local() + image;
        this->bmp = SDL_LoadBMP(this->img.c_str());
        SDL_SetColorKey(this->bmp, SDL_TRUE, SDL_MapRGB(this->bmp->format, 0x0a, 0x0a, 0x0a));
        this->tex = SDL_CreateTextureFromSurface(ren, this->bmp);
    }
    void blit(SDL_Renderer *ren){
        //std::cout << "blitting";
        SDL_RenderCopyEx(ren, this->tex, &this->pic, &this->loc, this->angle, &this->center, SDL_FLIP_NONE);
    }
};

但是,每当我运行程序时,将渲染器obj传递给它,它都无法渲染。有这样做的首选方式吗?我是不是太pythonic?

0 个答案:

没有答案