SDL2在C中转换SDL1.2代码,如何滚动窗口,以前是SDL_BlitSurface

时间:2016-11-18 16:44:31

标签: c sdl-2

我正在将SDL 1.2代码转换为C中的SDL 2,并且我遇到了滚动窗口(SDL 1.2 SDL_Surface,名为nanoglk_surface)文本的代码,以允许底部新行的空白空间:

  // Copy (scroll down).
  SDL_Rect r1 = { win->area.x, win->area.y + d,
                  win->area.w, win->area.h - d };
  SDL_Rect r2 = { win->area.x, win->area.y, win->area.w, win->area.h - d };
  SDL_BlitSurface(nanoglk_surface, &r1, nanoglk_surface, &r2);

  // Clear new, free area.
  SDL_Rect r = { win->area.x, win->area.y + win->area.h - d,
                 win->area.w, d };
  SDL_FillRect(nanoglk_surface, &r,
               SDL_MapRGB(nanoglk_surface->format,
                          win->bg[win->cur_styl].r,
                          win->bg[win->cur_styl].g,
                          win->bg[win->cur_styl].b));

这是开源C应用程序的一部分,在这里:https://github.com/BroadcastGames/nanoglk/blob/master/nanoglk/wintextbuffer.c - 整个应用程序在Ubuntu 16.04或16.10上编译并运行正常。但我正在尝试将其更新为SDL 2.0约定。

该应用只有一个窗口,其中包含相关的渲染器和纹理。做SDL_BlitSurface的SDL 2.0方式是什么?谢谢。

1 个答案:

答案 0 :(得分:0)

关于@genpfault在评论中链接的内容:

/* ... */
SDL_BlitSurface(src, &src_rect, dst, &dst_rect);
/* ... */

与(SDL2)相同:

/* ... */
// Create texture as late as possible to save resources:
SDL_Texture *src_texture = SDL_CreateTextureFromSurface(renderer_dst, src);
SDL_RenderCopy(renderer_dst, src_texture, &src_rect, &dst_rect);
// Destroy texture as soon as possible to save resources:
SDL_DestroyTexture(src_texture);
/* ... */
SDL_RenderPresent(render_dst);

你的blit将是硬件加速的。

相关问题