SDL2.0 一些名词解释

SDL_Window

SDL_Window is the struct that holds all info about the Window itself: size, position, full screen, borders etc.


SDL_Renderer

SDL_Renderer is a struct that handles all rendering. It is tied to a SDL_Window so it can only render within that SDL_Window. It also keeps track the settings related to the rendering. There are several important functions tied to the SDL_Renderer

  • SDL_SetRenderDrawColor(renderer, r, g, b, a);
    This sets the color you clear the screen to ( see below )

  • SDL_RenderClear(renderer);
    This clears the rendering target with the draw color set above

  • SDL_RenderCopy(
    This is probably the function you'll be using the most, it's used for rendering a SDL_Texture and has the following parameters :

    • SDL_Renderer* renderer,
      The renderer you want to use for rendering.
    • SDL_Texture* texture,
      The texture you want to render.
    • const SDL_Rect* srcrect, The part of the texture you want to render, NULL if you want to render the entire texture
    • const SDL_Rect* dstrect)
      Where you want to render the texture in the window. If the width and height of this SDL_Rect is smaller or larger than the dimensions of the texture itself, the texture will be stretched according to this SDL_Rect
  • SDL_RenderPresent(renderer);
    The other SDL_Render* functions draws to a hidden target. This function will take all of that and draw it in the window tied to the renderer.

SDL_Textures and SDL_Surface

The SDL_Renderer renders SDL_Texture, which stores the pixel information of one element. It's the new version of SDL_Surface which is much the same. The difference is mostly that SDL_Surface is just a struct containing pixel information, while SDL_Texture is an efficient, driver-specific representation of pixel data.

You can convert an SDL_Surface* to SDL_Texture using

SDL_Texture* SDL_CreateTextureFromSurface(SDL_Renderer* renderer,
                                          SDL_Surface*  surface)

After this, the SDL_Surface should be freed using

SDL_FreeSurface( SDL_Surface* surface )

Another important difference is that SDL_Surface uses software rendering (via CPU) while SDL_Texture uses hardware rendering (via GPU).


SDL_Rect

The simplest struct in SDL. It contains only four shorts. x, y which holds the position and w, hwhich holds width and height.

It's important to note that 0, 0 is the upper-left corner in SDL. So a higher y-value means lower, and the bottom-right corner will have the coordinate x + w, y + h

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值