SDL2.0官方推荐案例实战


***【在线视频教程】***

好文章,来自【福优学苑@音视频+流媒体】

SDL2.0官方推荐案例实战

TwinkebearDev SDL 2.0

TDSDLTutorial包含7个lesson。



https://github.com/Twinklebear/TwinklebearDev-Lessons


Lesson Index:

Lesson 0: Setting up SDL:

A simple program to make sure you've set up SDL correctly


Lesson 1: Hello World:

The standard Hello World program, for SDL 2.0


Lesson 2: Don't Put Everything in Main

An introduction to creating some functions to help us with writing better and reusable code.


Lesson 3: SDL Extension Libraries

An introduction to the various extension libraries that are available for SDL in this lesson we cover usage of SDL_image to load non-BMP images


Lesson 4: Handling Events

An introduction to using SDL's event system to get user input from the window, mouse and keyboard


Lesson 5: Clipping Sprite Sheets

An introduction to selecting specific subsets of an image sheet, ie. sprite sheet, that we want to draw


Lesson 6: True Type Fonts with SDL_ttf

An introduction to using the SDL_ttf extension library to render true type fonts



lesson0:SDL2.0开发环境的配置

lesson 0主要是关于SDL2.0开发环境的配置(visual studio、mingw、linux gcc等)。


请参考“SDL2.0小白入门亲手操练”的相关章节


#include <iostream>

#include <SDL.h>


/*

 * Lesson 0: Test to make sure SDL is setup properly

 */

int main(int, char**){

if (SDL_Init(SDL_INIT_VIDEO) != 0){

std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;

return 1;

}

SDL_Quit();


return 0;

}



lesson1:HelloWorld

lesson 1和lesson 2介绍了bmp图片的加载、SDL中视频渲染的基本原理以及SDL初始化销毁的方式,其中主要涉及window、render、texture、surface以及绘图的坐标系统。


SDL的核心对象

Window(主窗口)、

Render(GPU:硬件加速)、

texture(纹理:存储描述信息)、

surface(画布、内存中一块地址、存储像素数据)

SDL_CreateXXX

SDL_DestroyXXX



/// 渲染器:更新屏幕:三部曲 

//First clear the renderer

SDL_RenderClear(ren);

//Draw the texture

SDL_RenderCopy(ren, tex, NULL, NULL);

//Update the screen

SDL_RenderPresent(ren);




Lesson2:不要把所有东西都扔进Main函数

loadTexture(...)

renderTexture(...)


/// 创建纹理

SDL_CreateTextureFromSurface(render*, surface*);




lesson3:SDL_image扩展库

lesson 3介绍SDL_image扩展库的使用,主要是如何加载非BMP格式图片并导入到SDL texture。



SDL2_image:库

IMG_Init();

IMG_LoadTexture

IMG_Quit();




lesson4:SDL事件处理

lesson 4介绍了SDL input event(键盘、鼠标、窗口事件)的响应。





lesson5:SDL处理精灵图sprite

lesson 5 介绍了sprite的加载及动态切换(类动画效果)。



lesson6:字体扩展库SDL_ttf

lesson 6介绍了SDL_ttf扩展库的使用,用于在SDL中显示字体。

TTF_Init

TTF_OpenFont

TTF_RenderText_Blended

TTF_Quit




下载地址:

https://www.libsdl.org/projects/SDL_ttf/







好文章,来自【福优学苑@音视频+流媒体】
***【在线视频教程】***