Day10_Linux环境下的SDL2简介

返回目录

OpenTTD在Linux环境下通过SDL2来驱动显示,./openttd -d 2 启动后,我们可以看到以下日志,验证确实使用到 sdl ,大家可以试一下在windows环境下,启动命令行,看看下面的最后一行 video driver 后面显示的是什么内容。

游戏启动阶段创建窗口调用链
SDL_CreateWindow()
<- sdl2_v.cpp VideoDriver_SDL_Base::CreateMainWindow()
<- VideoDriver_SDL_Base::CreateMainSurface()
<- VideoDriver_SDL_Base::AfterBlitterChange()
<- gfxinit.cpp SwitchNewGRFBlitter()
<- gfxinit.cpp GfxLoadSprites()
<- genworld.cpp GenerateWorld()

https://www.willusher.io/pages/sdl2/ 可以学习到SDL2的基础知识,这个sample包含了 6个很有代表性的Lesson:
1.加载一个HelloWorld的bmp图片;
2. SDL_CreateRenderer()创建Render 后 通过 SDL_QueryTexture()和SDL_RenderCopy()贴图;
3. 使用SDL_Rect切割屏幕为一个个小方块然后 贴图(openttd的Tile使用了这个原理);
4.SDL_Event 捕获用户交互事件;
5.键盘1-4,对应截取图片的一部分,贴图到界面上;
6. TTF输出指定的字体;

下面是Sample用到的函数和 数据清单, 其中后面带 (*) 是Openttd用到的函数和数据类型。

Function:
SDL_GetError(): Log an SDL error ()
SDL_Init(): Start up SDL (
)
SDL_CreateWindow(): Setup window ()
SDL_CreateRenderer(): Setup xrenderer
SDL_CreateTextureFromSurface(): Create
SDL_QueryTexture(): Query the texture to get its width and height to use
SDL_RenderCopy(): Draw an SDL_Texture to an SDL_Renderer at some destination rect
SDL_FreeSurface(): Clean up the surface (
)
SDL_RenderPresent(): Update the screen
SDL_Delay(): Take a quick break after all that hard work
SDL_RenderClear: Clean up Render
SDL_LoadBMP: Load the image (* - only when creating window)
SDL_Quit(): Clean up SDL
IMG_LoadTexture(): Loads an image into a texture on the rendering device
IMG_Quit(): Clean up IMG
TTF_Init(): Start up TTF
TTF_OpenFont(): Open the font
TTF_RenderText_Blended(): load that surface into a texture
TTF_CloseFont(): Clean up the font
TTF_Quit():Clean up TTF

DataType:
SDL_Rect: the destination rectangle to be at the position we want ()
SDL_Window: call OS for opening a window(
)
SDL_Renderer: 渲染器
SDL_Texture: texture on the rendering device
SDL_Surface: for loaded image or font ()
SDL_Color: color for font (
)
SDL_KEYDOWN: user presses any key ()
SDL_MOUSEBUTTONDOWN: user clicks the mouse (
)

参考:
https://blog.csdn.net/qq_25333681/article/details/89789707 SDL2常用函数&结构分析:SDL_BlitSurface&SDL_UpdateWindowSurface
https://www.5axxw.com/questions/content/5qgr4t 如何用make用sdl2库构建项目?
https://www.willusher.io/pages/sdl2/ (***)TwinklebearDev SDL 2.0 Tutorial Index
https://github.com/Twinklebear/TwinklebearDev-Lessons 楼上的sample code
https://blog.csdn.net/xingdou520/article/details/84861026 【Debug】:ERROR:Could NOT find SDL2 (missing: SDL2_LIBRARY SDL2_INCLUDE_DIR)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值