开发者

SDL_Surface pointer passing between two classes

If I declare a SDL_Surface pointer in a class, can i share it with another class to draw on it in somehow?

class foo{
    private:
     SDL_Surface* mainScreen;
    public:
     foo() {
      mainScreen = SDL_SetVideoMode(400,300,32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL);
     }

     ~fo开发者_运维技巧o() {
      SDL_FreeSurface(mainScreen);
     }

     SDL_Surface* getSurf() {
      return mainScreen;
     }

};

class fee{
    private:
     SDL_Surface* screen_passed;
    public:
     void draw(SDL_Surface* screen) {
      screen_passed = screen;

      SDL_Surface* img;
      SDL_Surface* app;
      app = IMG_Load("image.png");
      img = SDL_DisplayFormatAlpha(app);
      SDL_FreeSurface(app);
      SDL_Rect destR;

      destR.x=0;
      destR.y=0;

      SDL_BlitSurface(img, NULL, screen, &destR);
     }
};

int main(int argc, char* argv[]) {
     SDL_Init(SDL_INIT_VIDEO);
     foo a;
     fee b;
     b.draw(a.getSurf());
     SDL_Flip(a.getSurf());
     sleep(5);
     return 0;
}

compiles and run, but the screen is black, can anyone help?


Screen is black probably because you're using double buffering and never flip the buffer (call SDL_Flip(a.getSurf()) after b.draw).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜