總結 SDL筆記

2021-08-02 20:41:41 字數 2817 閱讀 2044

這裡總結一下個人對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

sdl_su***ce*su***ce=img_load(char*file);

4.載入文字:

//文字風格:斜體。另外 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:

//su***ce轉換成texture

sdl_texture*texture=sdl_createtexturefromsuface(sdl_renderer*renderer, sdl_su***ce*su***ce);

//獲取texture的長寬的with,height;

sdl_querytexture(sdl_texture*texture, null, null, &with, &height);

6.su***ce:

//銷毀

sdl_freesu***ce(sdl_su***ce*su***ce);

7.設定su***ce和texture的透明度:

sdl_setsu***ceblendmode(sdl_su***ce*su***ce, sdl_blendmode_blend);

sdl_setsu***cealphamod(sdl_su***ce*su***ce, 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);

SDL學習筆記之二

sdl su ce image sdl loadbmp image.bmp 2.從乙個表面,進行塊複製到另乙個表面 sdl blitsu ce int sdl blitsu ce sdl su ce src,sdl rect sr,sdl su e dst,sdl rect dr 第二個引數指定要傳...

SDL學習筆記之二

sdl su ce image sdl loadbmp image.bmp 2.從乙個表面,進行塊複製到另乙個表面 sdl blitsu ce int sdl blitsu ce sdl su ce src,sdl rect sr,sdl su e dst,sdl rect dr 第二個引數指定要傳...

sdl環境安裝學習筆記

一 簡介 二 配置 sudo apt get install libsdl1.2 dev 附加包 sudo apt get install libsdl image1.2 dev sudo apt get install libsdl mixer1.2 dev sudo apt get instal...