• SDL操作笔记


    原文地址:https://blog.csdn.net/qq_38124598/article/details/73543184

    这里总结一下个人对SDL的一些函数,方便以后查询。

      v1.0.1

    1.窗口:


    SDL_Init(SDL_INIT_VIDEO);
    //创建窗口
    SDL_Window*window=SDL_CreateWindow(char*title,int x, int y, int width, int height,0);
    //获取窗口大小
    int win_w,win_h;SDL_GetWindowSize(window,&win_w,&win_h);
    //销毁窗口
    SDL_DestroyWindow(window);
    SDL_Quit();
     
        2.渲染器:
    //创建
    SDL_Renderer*renderer=SDL_CreateRenderer(window,-1,0);
    //设置透明度
    SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
    //清理
    SDL_RenderClear(renderer);
    //刷新
    SDL_RenderPresent(renderer);
    //销毁
    SDL_DestroyRenderer(renderer);
     
     
      3.加载图片:

    #include <SDL2/SDL_image.h>
    SDL_Surface*surface=IMG_Load(char*file);
     

      4.加载文字:
    #include <SDL2/SDL_ttf.h>
    TTF_Init();
    TTF_Font*font=TTF_OpenFont(char*file, int size);
    SDL_Surface*surface=TTF_RenderUTF8_Blended_Wrapped(TTF_Font*font, chae*str, SDL_Color color, int width);
     
    //文字风格:斜体。另外 TTF_STYLE_BOLD:粗体,TTF_STYLE_UNDERLINE:下划线,TTF_STYLE_STRIKETHROUGH:删除线,TTF_STRLE_NORMAL:正常
    TTF_SetFontStyle(TTF_Font*font, TTF_STYLE_ITALIC);
    //退出
    TTF_CloseFont(font);TTF_Quit();
     
     
      5.texture:

    //surface转换成texture
    SDL_Texture*texture=SDL_CreateTextureFromSuface(SDL_Renderer*renderer, SDL_Surface*surface);
    //获取texture的长宽的with,height;
    SDL_QueryTexture(SDL_Texture*texture, NULL, NULL, &with, &height);
     
      6.surface:
    //销毁
    SDL_FreeSurface(SDL_Surface*surface);

      7.设置surface和texture的透明度:
    SDL_SetSurfaceBlendMode(SDL_Surface*surface, SDL_BLENDMODE_BLEND);
    SDL_SetSurfaceAlphaMod(SDL_Surface*surface, Uint8 alpha);
    SDL_SetTextureBlendMode(SDL_Texture*texture, SDL_BLENDMODE_BLEND);
    SDL_SetTextureAlphaMod(SDL_Texture*texture, Uint8 alpha);
     

      8.画画:
    SDL_SetRenderDrawColor(SDL_Renderer*renderer, Uint8 r,Uint8 g, Uint8 b, Uint8 a); //设置画笔颜色
    SDL_FillRect(SDL_Renderer*renderer, SDL_Rect*rect); //填充矩形
     

      9.在texture上画画:

    SDL_Texture*texture=SDL_CreateTexture(SDL_Renderer*renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, int width, int height);
    SDL_SetRenderDrawColor(SDL_Renderer*renderer, 255, 255, 255, 0);
    SDL_SetRenderTarget(SDL_Renderer*renderer, SDL_Texture*texture);
    SDL_RenderClear(SDL_Renderer*renderer);
    ...//画画
    SDL_SetRenderTarget(SDL_Renderer*renderer, NULL);
     
  • 相关阅读:
    语言混编总结二
    可执行文件与符号(表)
    iOS错误报告中关于崩溃地址的分析
    Find the build UUID in a Crash Report
    Symbolicating Crash Reports With atos
    iOS crash log 解析 symbol address = stack address
    Address space layout randomization
    ASLR(Address space layout randomization)地址空间布局随机化
    缓冲区溢出详解
    如何快速查看将C反汇编的代码
  • 原文地址:https://www.cnblogs.com/boonya/p/9253352.html
Copyright © 2020-2023  润新知