精华内容
下载资源
问答
  • SDL 介绍

    2020-12-27 00:49:30
    一、SDL的使用 加头文件 #include<SDL.h> 初始化SDL 退出SDL SDL 主要用在渲染 SDL 渲染窗口 初始化:SDL_Init(),SDL_Quit() 创建窗口:SDL_CreatWindow() 销毁窗口, SDL_DestoryWindow() 创建一个...

    目录

    一、SDL的使用

    二、SDL 窗口的渲染

    三、SDL 事件基本原理

    四、纹理渲染

    渲染基本原理

    五、实现YUV播放器

    六、SDL播放音频(PCM数据)


    一、SDL的使用

    加头文件 #include<SDL.h>

    初始化SDL

    退出SDL

    SDL 主要用在渲染

    SDL 渲染窗口

    初始化:SDL_Init(),SDL_Quit()

    创建窗口:SDL_CreatWindow()    销毁窗口, SDL_DestoryWindow()

    创建一个渲染器:SDL_CreateRender(),作用是把图像帧会到窗口里面去。

    int main(){
    
    SDL_window *window =NULL;
    
    SDL_Init(SDL_INIT_VIDEO) ;
    
    //200,200 显示的位置
    //640,680,窗口宽高,
    //SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER:窗口标志位
    window =SDL_Createwindow("window_title",200,200,640,480,SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER);
    
    if(!window){
        goto __EXIT;
    }
    
    SDL_DestoryWindow(windou);//销毁窗口
    
    __EXIT:
        SDL_Quit() ;
        return 0;
    
    }

    以上一段代码其实是在系统内存里面分配了一块空间,要将东西显示出来,就要去渲染,把结果填入这个window内存里。

    二、SDL 窗口的渲染:

    所以就要创建一个渲染器:SDL_CreateRender()   ,销毁一个渲染器:SDL_DestoryRender()

    SDL_RenderClear();这个方法要调用一下,避免里面有一些脏数据。

    SDL_RenderPresent():把数据推送到驱动。(其实是先推到平台的引擎去,引擎再拷贝到显卡驱动,再到屏幕)

    int main(){
    
    SDL_window *window =NULL;
    SDL_Renderer *render =NULL;
    
    SDL_Init(SDL_INIT_VIDEO) ;
    
    //200,200 显示的位置
    //640,680,窗口宽高,
    //SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER:窗口标志位
    window =SDL_Createwindow("window_title",200,200,640,480,SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER);
    
    if(!window){
        goto __EXIT;
    }
    
    render  = SDL_CreateRender(window,-1,0);
    
    SDL_SetRenderDrawColor(render,255,0,0,255/*透明度,255不退出*/);//换个红色
    
    SDL_RenderClear(render);//把之前的数据清掉
    
    SDL_RenderPresent(render);
    
    SDL_Delay(30000);//延时显示30S
    
    SDL_DestoryWindow(windou);//销毁窗口
    
    __EXIT:
        SDL_Quit() ;
        return 0;
    
    }

    三、SDL 事件基本原理:

    SDL  将所有的事件都存放在一个队列中。所有对事件的操作,其实就是对队列的操作,基本对事件的处理都是这样的。

    SDL 事件种类

    SDL_WindowEvent:窗口事件,如全屏,最小化,关闭窗口

    SDL_KeyboardEvent: 键盘事件

    SDL_MouseMotionEvent:鼠标事件

    SDL如何处理事件:

    SDL_PollEvent  :轮询 传统的方式,用一个线程处理这个队列,比如每隔一秒去检测一下队列,看队列里面是否有事件了,有事件就处理。轮询这种方式有一个问题就是处理的不够及时。

    SDL_WaitEvent :事件触发机制,当有一个事件来了之后,就发送一个信号,有一个线程在监听这个信号,这个线程会被激活,那么这个事件就会立马被处理。

    SDL_WaitEventTimeout。SDL_WaitEvent的完善,设置一个等待时间,如果操作这个时间没有事件过来,就主动去查看一下,避免事件因为默写原因卡了,又导致队列其他事件不能上来。

    int main(){
    
    SDL_window *window =NULL;
    SDL_Renderer *render =NULL;
    int quit=1;
    SDL_Event event;
    
    SDL_Init(SDL_INIT_VIDEO) ;
    
    //200,200 显示的位置
    //640,680,窗口宽高,
    //SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER:窗口标志位
    window =SDL_Createwindow("window_title",200,200,640,480,SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER);
    
    if(!window){
        goto __EXIT;
    }
    
    render  = SDL_CreateRender(window,-1,0);
    
    SDL_SetRenderDrawColor(render,255,0,0,255/*透明度,255不退出*/);//换个红色
    
    SDL_RenderClear(render);//把之前的数据清掉
    
    SDL_RenderPresent(render);
    
    //SDL_Delay(30000);//延时显示30S
    
    do{//添加事件监听
        
        SDL_WaitEvent(&event);
        switch(event.type){
        case SDL_QUIT:
            quite=0;
            break;
        default:
            
            SDL_Log("event type is %d",event.type);
        }
    }while(quit);
    
    SDL_DestoryWindow(windou);//销毁窗口
    
    __EXIT:
        SDL_Quit() ;
        return 0;
    
    }

    四、纹理渲染:

    假设画一条直线,这条直线有起点,终点。线有渐变的颜色。对于RGB 来说,每一个像素点都要被描述出来,R,G,B 每个有个成分是多少,都要直接填在内存,这就显得数据非常大了。对于纹理来说,他不会这么描述这么一条线,他只会告诉你这条线的起点,终点的位置,中间的颜色是怎么渐变的,它会将这些描述信息直接告诉显卡。所以,这条线全部占用的内存很小,非常节约内存。这些渐变信息,通过显卡GPU的计算,得到的数据,就是RGB 的数据了。

    渲染基本原理:

    图像通过渲染器,把内存中的图变成纹理,这样我们就有了描述这种图的数据了,有了纹理后,我们就把它交到显卡,显卡通过计算还原成RGB 最终放到窗口显示。

    SDL纹理相关API:

    SDL_CreateTexture() :创建纹理

    参数,format:YUV ,RGB

               access:Texture 类型,即是Target ,还是Stream 呢,Stream 表示视屏

    SDL_DestroyTexTure():销毁纹理

    SDL 渲染相关的API:

    SDL_SetRenderTartget():往哪儿渲染,默认的是我们绘制的window上渲染。但是我们使用纹理,我们就要把目标改成TexTure,往纹理上渲染。

    SDL_RenderClear()。

    SDL_RenderCopy():将纹理拷贝到显卡上,显卡开始计算出最终图形

    SDL_RenderPresent() :显卡计算出最终图形后,我们可以控制它,最终要不要渲染到窗口上。要不要投影到显示器上。

    int main(){
    
    SDL_window *window =NULL;
    SDL_Renderer *render =NULL;
    SDL_Texture * texture =NULL;
    int quit=1;
    SDL_Event event;
    SDL_Rect rect;
    SDL_Init(SDL_INIT_VIDEO) ;
    
    //200,200 显示的位置
    //640,680,窗口宽高,
    //SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER:窗口标志位
    window =SDL_Createwindow("window_title",200,200,640,480,SDL_WINDOW_SHOWN|SDL_WINDOW_BORDER);
    
    if(!window){
        goto __EXIT;
    }
    
    render  = SDL_CreateRender(window,-1,0);//-1,0 暂时不用理解
    if(!render){
        SDL_Log(“failed 头 create Render!”);
        goto __DWINDOW;
    }
    
    
    /*
    SDL_SetRenderDrawColor(render,255,0,0,255/*透明度,255不退出*/);//换个红色
    
    SDL_RenderClear(render);//把之前的数据清掉
    
    SDL_RenderPresent(render);*/
    
    //SDL_Delay(30000);//延时显示30S
     texture = SDL_CreateTexture(render,SDL_PIXELFORMAT_RGBA8888,
                                                     SDL_TEXTUREACCESS_TARGET,
                                                        640,480);
    if(!texture){
        SDL_Log(“failed 头 create Texture!”);
        goto __RENDER;
    }
    
    do{//添加事件监听
        
        SDL_WaitEvent(&event);
        switch(event.type){
        case SDL_QUIT:
            quite=0;
            break;
        default:
            
            SDL_Log("event type is %d",event.type);
        }
    
        
        rect.w=30;
        rect.h=30;
        rect.x=rand()%600;
        recty=rand()%450;
        
        //
        SDL_SetRenderTarget(render,texture);//改变渲染的目标是纹理
        SDL_SetRenderDrawColor(render,0,0,0,0)//设置背景颜色
        SDL_RenderClear(rener);
    
        SDL_RenderDrawRect(render,&rect);//画方块
        SDL_SetRenderDrawColor(render,255,0,0,0)//把方块设置成红色
        SDL_RenderFillRect(render,&rect);/填充方块
    
        SDL_SetRenderTarget(render,NULL);//把纹理渲染到窗口去,这个时候,恢复成默认的window
        SDL_RenderCopy(render,texture,NULL,NULL)//把纹理交给显卡
    
        SDL_RenderPresent(render);//显卡计算完,显不显示,由着个函数决定
        
    }while(quit);
    
    SDL_DestroyTexture(texture);
    
    
    
    __RENDER:
        
    __DWINDOW:
        SDL_DestoryWindow(windou);//销毁窗口
    
    __EXIT:
        SDL_Quit() ;
        return 0;
    
    }

    五、实现YUV播放器

    ①创建线程

    SDL_CreateThread() 

    fn:线程函数

    name: 线程名字

    data:执行函数参数

    ②SDL 更新纹理,创建销毁前面讲过 了,更新是什么呢?对于视屏播放的时候,1秒钟会播放很多帧,对于每一帧的图片的变更,我们都要更新一次纹理

    SDL_UpdateTexture() :参数是 图片的起始地址,和宽度

    SDL_UpdateYUVTexture():效率高,参数是很多Y 分量地址,U分量地址,V分量地址 ....

    ③YUV 知识

    YUV444 :4个Y分量对应4个U分量对应4个V分量,为1:1:1.。

    YUV420:4个Y分量对应2个U分量对应0个V分量,再4个Y分量对应0个U分量对应2个V分量

    YUV 的存储模式:平坦模式,交叉模式

    ④实现框架

    25帧的视频,那么就是40ms 一副图片要被送去渲染,

    设置一个线程,控制播放速度。40ms触发一次事件,事件通知到主线程,主线程收到这个消息之后,就去SDL_UpdateTexture ,更新一下下一幅图片。

    #include <stdio.h>
    #include <string.h>
    
    #include <SDL.h>
    
    const int bpp=12;
    
    int screen_w=500,screen_h=500;
    
    #define BLOCK_SIZE 4096000
    
    //event message
    #define REFRESH_EVENT  (SDL_USEREVENT + 1)
    #define QUIT_EVENT  (SDL_USEREVENT + 2)
    
    int thread_exit=0;
    
    int refresh_video_timer(void *udata){
    
        thread_exit=0;
    
        while (!thread_exit) {
            SDL_Event event;
            event.type = REFRESH_EVENT;
            SDL_PushEvent(&event);
            SDL_Delay(40);
        }
    
        thread_exit=0;
    
        //push quit event
        SDL_Event event;
        event.type = QUIT_EVENT;
        SDL_PushEvent(&event);
    
        return 0;
    }
    
    int main(int argc, char* argv[])
    {
    
        FILE *video_fd = NULL;
    
        SDL_Event event;
        SDL_Rect rect;
    
        Uint32 pixformat = 0;
    
        SDL_Window *win = NULL;
        SDL_Renderer *renderer = NULL;
        SDL_Texture *texture = NULL;
    
        SDL_Thread *timer_thread = NULL;
    
        int w_width = 640; w_height = 480;
        const int video_width = 320, video_height = 180;
    
        Uint8 *video_pos = NULL;
        Uint8 *video_end = NULL;
    
        unsigned int remain_len = 0;
        unsigned int video_buff_len = 0;
        unsigned int blank space_len = 0;
        Uint8 *video_buf[BLOCK_SIZE];
    
        const char *path = "test_yuv420p_320x180.yuv";
    
        const unsigned int yuv_frame_len = video_width * video_height * 12 / 8;
    
        //initialize SDL
        if(SDL_Init(SDL_INIT_VIDEO)) {
            fprintf( stderr, "Could not initialize SDL - %s\n", SDL_GetError());
            return -1;
        }
    
        //creat window from SDL
        win = SDL_CreateWindow("YUV Player",
                               SDL_WINDOWPOS_UNDEFINED,
                               SDL_WINDOWPOS_UNDEFINED,
                               w_width, w_height,
                               SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
        if(!win) {
            fprintf(stderr, "Failed to create window, %s\n",SDL_GetError());
            goto __FAIL;
        }
    
        renderer = SDL_CreateRenderer(screen, -1, 0);
    
        //IYUV: Y + U + V  (3 planes)
        //YV12: Y + V + U  (3 planes)
        pixformat= SDL_PIXELFORMAT_IYUV;
    
        //create texture for render
        texture = SDL_CreateTexture(renderer,
                                    pixformat,
                                    SDL_TEXTUREACCESS_STREAMING,
                                    video_width,
                                    video_height);
    
        //open yuv file
        video_fd = fopen(path, "r");
        if( !video_fd ){
            fprintf(stderr, "Failed to open yuv file\n");
            goto __FAIL;
        }
    
        //read block data
        if(video_buff_len = fread(video_buf, 1, BLOCK_SIZE, video_fd) <= 0){
            fprintf(stderr, "Failed to read data from yuv file!\n");
            goto __FAIL;
        }
    
        //set video positon
        video_pos = video_buf;
        video_end = video_buf + video_buff_len;
        blank_space_len = BLOCK_SIZE - video_buff_len;
    
        timer_thread = SDL_CreateThread(refresh_video_timer,
                                        NULL,
                                        NULL);
    
        do {
            //Wait
            SDL_WaitEvent(&event);
            if(event.type==REFRESH_EVENT){
                //not enought data to render
                if((video_pos + yuv_frame_len) > video_end){
    
                    //have remain data, but there isn't space
                    remain_len = video_end - video_pos;
                    if(remain_len && !black_space_len) {
                        //copy data to header of buffer
                        memcpy(video_buf, video_pos, remain_len);
    
                        blank_space_len = BLOCK_SIZE - remain_len;
                        video_pos = video_buf;
                        video_end = video_buf + remain_len;
                    }
    
                    //at the end of buffer, so rotate to header of buffer
                    if(video_end == (video_buf + BLOCK_SIZE)){
                        video_pos = video_buf;
                        video_end = video_buf;
                        blank_space_len = BLOCK_SIZE;
                    }
    
                    //read data from yuv file to buffer
                    if(video_buff_len = fread(video_end, 1, blank_space_len, video_fd) <= 0){
                        fprintf(stderr, "eof, exit thread!");
                        thread_exit = 1;
                        continue;// to wait event for exiting
                    }
    
                    //reset video_end
                    video_end += video_buff_len;
                }
    
                SDL_UpdateTexture( texture, NULL, video_pos, video_width);
    
                //FIX: If window is resize
                rect.x = 0;
                rect.y = 0;
                rect.w = w_width;
                rect.h = w_height;
    
                SDL_RenderClear( renderer );
                SDL_RenderCopy( renderer, texture, NULL, &rect);
                SDL_RenderPresent( renderer );
    
            }else if(event.type==SDL_WINDOWEVENT){
                //If Resize
                SDL_GetWindowSize(win, &w_width, &w_height);
            }else if(event.type==SDL_QUIT){
                thread_exit=1;
            }else if(event.type==QUIT_EVENT){
                break;
            }
        }while ( 1 );
    
    __FAIL:
    
        //close file
        if(video_fd){
            fclose(video_fd);
        }
    
        SDL_Quit();
    
        return 0;
    }
    
    

     

    六、SDL播放音频(PCM数据)

     

    播放音频的基本原则:

    声卡向你要数据而不是你主动推给声卡,声卡播放完了数据,会回调一个函数,告诉你我需要数据了。在这个函数里,把数据放到它指定的buffer里面。

    推送的数据多少由音频参数决定的

    SDL 音频API :

    SDL_OpenAudio():打开音频设备

    SDL_CloseAudio():关闭音频设备

    SDL_PauseAudio():开始、暂停播放

    SDL_MixAudio():混音,将多路的音频混在一起输给声卡。可以理解为把数据拷贝到声卡设备

    实现PCM播放器:

    #include <stdio.h>
    #include <SDL.h>
    
    #define BLOCK_SIZE 4096000
    
    static Uint8 *audio_buf = NULL;
    static Uint8 *audio_pos = NULL;
    static size_t buffer_len = 0;
    
    //callback function for audio devcie
    void read_audio_data(void *udata, Uint8 *stream, int len){
    
        if(buffer_len == 0){
            return;
        }
    
        SDL_memset(stream, 0, len);//对stream清零
    
        len = (len < buffer_len) ? len : buffer_len;
    	//SDL_MIX_MAXVOLUME 设置音量
        SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);//把数据拷贝到stream
    
        audio_pos += len;
        buffer_len -= len;
    }
    
    
    int main(int argc, char *argv[])
    {
        int ret = -1;
    
        FILE *audio_fd = NULL;
    
        SDL_AudioSpec spec;
    
        char *path = "./test.pcm";
    
        //SDL initialize,对音频,视屏等初始化
        if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)){
            fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
            return ret;
        }
    
        //open pcm file
        audio_fd = fopen(path, "r");
        if(!audio_fd){
            fprintf(stderr, "Failed to open pcm file!\n");
            goto __FAIL;
        }
    
        //alloc memory for audio
        audio_buf = (Uint8*)malloc(BLOCK_SIZE);
        if(!audio_buf){
            goto __FAIL;
        }
    
        //SDL_AudioSpec
        spec.freq = 44100;;
        spec.format = AUDIO_S16SYS;//16位
        spec.channels = 2;
        spec.silence = 0;
        spec.samples = 2048;;
        spec.callback = read_audio_data;;
        spec.userdata = NULL;//回调回来的参数,目前不需要
    
        //open audio devcie
        if(SDL_OpenAudio(&spec, NULL)){
            fprintf(stderr, "Failed to open audio device, %s\n", SDL_GetError());
            goto __FAIL;
        }
    
        //play audio
        SDL_PauseAudio(0);//0,表示播放  1表示暂停
    
        do{
            //read data from pcm file
            buffer_len = fread(audio_buf, 1, BLOCK_SIZE, audio_fd);
            fprintf(stderr, "block size is %zu\n", buffer_len);
    
            audio_pos = audio_buf;
    
            //the main thread wait for a moment
            while(audio_pos < (audio_buf + buffer_len)) {//说明audio_buf 里面还有数据,等设备先消耗数据,直到audio_pos = (audio_buf + buffer_len),数据消耗完了,我们在从audio_fd里面读取数据。还有一种算法是,设备消耗了多少,这边补多少数据在audio_buf,比较难一点。
                SDL_Delay(1);
            }
    
        }while(buffer_len !=0);
    
        //close audio device
        SDL_CloseAudio();//这里需要优化。
    
        ret = 0;
    
    __FAIL:
        //release some resources
        if(audio_buf){
            free(audio_buf);
        }
    
        if(audio_fd){
            fclose(audio_fd);
        }
    
        //quit SDL
        SDL_Quit();
    
        return ret;
    }
    
    
    

    SDL 初步学习到这儿。

    展开全文
  • //Takes key presses and adjusts the dot's velocity void handleEvent( SDL_Event& e ); //Moves the dot void move(); //Shows the dot on the screen relative to the camera void render( int camX, int camY ...

    滚动

    到目前为止,我们只涉及屏幕大小的平面。有了滚动功能,你可以通过渲染与摄影机相关的所有内容来浏览任何大小的平面。

    滚动的基本原理是,你有一个矩形,它的功能是一个摄像机:

    然后你只渲染摄像机里的东西,通常涉及渲染相对于摄像机的事物或仅显示摄像机内部的对象的一部分。

    //平面的尺寸
    const int LEVEL_WIDTH = 1280;
    const int LEVEL_HEIGHT = 960;
    
    //屏幕尺寸常量
    const int SCREEN_WIDTH = 640;
    const int SCREEN_HEIGHT = 480;
    

    由于平面不再是屏幕的大小,我们必须有一组单独的常量来定义平面的大小。

    //The dot that will move around on the screen
    class Dot
    {
        public:
            //The dimensions of the dot
            static const int DOT_WIDTH = 20;
            static const int DOT_HEIGHT = 20;
    
            //Maximum axis velocity of the dot
            static const int DOT_VEL = 10;
    
            //Initializes the variables
            Dot();
    
            //Takes key presses and adjusts the dot's velocity
            void handleEvent( SDL_Event& e );
    
            //Moves the dot
            void move();
    
            //Shows the dot on the screen relative to the camera
            void render( int camX, int camY );
    
            //Position accessors
            int getPosX();
            int getPosY();
    
        private:
            //The X and Y offsets of the dot
            int mPosX, mPosY;
    
            //The velocity of the dot
            int mVelX, mVelY;
    };
    

    这一次,点要相对于摄像机进行渲染,所以它的渲染功能要考虑到摄像机的位置。

    void Dot::move(){
        //Move the dot left or right
        mPosX += mVelX;
    
        //If the dot went too far to the left or right
        if( ( mPosX < 0 ) || ( mPosX + DOT_WIDTH > LEVEL_WIDTH ) )
        {
            //Move back
            mPosX -= mVelX;
        }
    
        //Move the dot up or down
        mPosY += mVelY;
    
        //If the dot went too far up or down
        if( ( mPosY < 0 ) || ( mPosY + DOT_HEIGHT > LEVEL_HEIGHT ) )
        {
            //Move back
            mPosY -= mVelY;
        }
    }
    

    这次在移动点时,我们检查点是否从平面上移开,而不是检查点是否从屏幕上移开,因为屏幕要在平面上移动。

    void Dot::render( int camX, int camY ){
        //显示点相对于摄像机的位置
        gDotTexture.render( mPosX - camX, mPosY - camY );
    }
    

    现在,当我们将对象渲染到屏幕上时,我们通过减去摄像机的偏移来渲染它们相对于摄像机的位置。

                //Main loop flag
                bool quit = false;
    
                //Event handler
                SDL_Event e;
    
                //The dot that will be moving around on the screen
                Dot dot;
    
                //摄像机区域
                SDL_Rect camera = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };
    

    在进入主循环之前,我们先声明点和将要跟随它的摄像机。

                    //Move the dot
                    dot.move();
    
                    //将相机对准点的中心
                    camera.x = ( dot.getPosX() + Dot::DOT_WIDTH / 2 ) - SCREEN_WIDTH / 2;
                    camera.y = ( dot.getPosY() + Dot::DOT_HEIGHT / 2 ) - SCREEN_HEIGHT / 2;
    
                    //摄像机要保持在范围内
                    if( camera.x < 0 )
                    { 
                        camera.x = 0;
                    }
                    if( camera.y < 0 )
                    {
                        camera.y = 0;
                    }
                    if( camera.x > LEVEL_WIDTH - camera.w )
                    {
                        camera.x = LEVEL_WIDTH - camera.w;
                    }
                    if( camera.y > LEVEL_HEIGHT - camera.h )
                    {
                        camera.y = LEVEL_HEIGHT - camera.h;
                    }
    

    在我们移动点后,我们要将摄像机的位置改为点的中心位置。我们不希望摄像机离开平面,所以在移动它之后,我们要将它保持在边界内。

                    //Clear screen
                    SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
                    SDL_RenderClear( gRenderer );
    
                    //Render background
                    gBGTexture.render( 0, 0, &camera );
    
                    //Render objects
                    dot.render( camera.x, camera.y );
    
                    //Update screen
                    SDL_RenderPresent( gRenderer );
    

    摄像机到位后,我们渲染该摄像机内部的那部分背景,然后渲染相对于摄像机位置的点。

    这里下载本教程的媒体和源代码。

    原文链接

    关注我的公众号:编程之路从0到1
    编程之路从0到1

    展开全文
  • SDL_UpdateTexture,SDL_UpdateYUVTexture截屏效率比较

    两个初始化方式:

    方式1

    m_sdlwindow_output = SDL_CreateWindow("test", 0, 0, m_cfg.encwidth, m_cfg.encheight, SDL_WINDOW_BORDERLESS);
    assert(m_sdlwindow_output > 0);
    SDL_HideWindow(m_sdlwindow_output);
    m_sdlsurface_output = SDL_GetWindowSurface(m_sdlwindow_output);
    assert(m_sdlsurface_output > 0);
    m_sdlrenderer_output = SDL_CreateRenderer(m_sdlwindow_output, -1, SDL_RENDERER_ACCELERATED);
    assert(m_sdlrenderer_output > 0);

    这个方式走的是硬件渲染

    方式2

     m_sdlsurface_output = SDL_CreateRGBSurface(SDL_SWSURFACE, m_cfg.encwidth, m_cfg.encheight, 32, 0, 0, 0, 0);
     assert(m_sdlsurface_output != NULL);
     m_sdlrenderer_output = SDL_CreateSoftwareRenderer(m_sdlsurface_output);
     assert(m_sdlrenderer_output != NULL);

     //m_sdltexture_output = SDL_CreateTexture(m_sdlrenderer_output, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_TARGET,
     m_sdltexture_output = SDL_CreateTexture(m_sdlrenderer_output, SDL_PIXELFORMAT_RGB24, SDL_TEXTUREACCESS_TARGET,
      m_cfg.encwidth, m_cfg.encheight);
     assert(m_sdltexture_output != NULL);

    这个走的是软件渲染

    方式1,渲染速度非常快1毫秒多,1080p分辨率,但是此种方式用sdl_surface.savebmp,保存的是黑屏,

    方式1,渲染速度非常慢,因为实在软件上渲染,15毫秒,1080p分辨率,但是此种方式用sdl_surface.savebmp,可以保存到正确的图像。


     int pitch0 = g_ptrMainWnd->m_cfg.encwidth * SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_RGB24);

     DWORD dw1 = GetTickCount();

     //for (int m = 0; m < 1000; m++)
     {
      //ret = SDL_UpdateYUVTexture(g_ptrMainWnd->m_sdltexture_output, &g_ptrMainWnd->m_ptrActList[chnIdx]->m_outputTun.rect,
      // data_in[0], linesize_in[0],
      // data_in[1], linesize_in[1],
      // data_in[2], linesize_in[2]);
      //assert(ret == 0);


      ret = SDL_UpdateTexture(g_ptrMainWnd->m_sdltexture_output, &g_ptrMainWnd->m_ptrActList[chnIdx]->m_outputTun.rect,
       data_in[0], pitch0);
      // data_in[1], linesize_in[1],
      // data_in[2], linesize_in[2]);
      assert(ret == 0);



    同样是软件上渲染更新纹理时候也是两种方式,yuv稍快,15毫秒一帧,rgb24方式要30毫秒一帧。1080p的分辨率






    
    展开全文
  • sdl lesson

    2018-04-06 18:29:00
    #include <iostream>...SDL.h> #include <windows.h> /* * Lesson 0: Test to make sure SDL is setup properly */ //#define LESSON_5 //#define LESSON_4 //#define LESSON...
    #include <iostream>
    #include <SDL.h>
    #include <windows.h>
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
     
     
    //#define LESSON_5
    //#define LESSON_4
    //#define LESSON_3
    //#define LESSON_2
    //#define LESSON_1
    //#define LESSON_0
     
     
     
     
     
     
     
     
    #ifdef LESSON_5
    #include <iostream>
    #include <SDL.h>
    #include <SDL_image.h>
    using namespace std;
     
     
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
     
     
     
     
    const int SCREEN_WIDTH  = 640;
    const int SCREEN_HEIGHT = 480;
    //We'll just be using square tiles for now
    const int TILE_SIZE = 40;
     
     
    void logSDLError(std::ostream &os, const std::string &msg)
    {
        os << msg << " error: " << SDL_GetError() << std::endl;
    }
     
     
    SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
        SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
        if (texture == nullptr){
            logSDLError(std::cout, "LoadTexture");
        }
        return texture;
    }
    void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){
        //Setup the destination rectangle to be at the position we want
        SDL_Rect dst;
        dst.x = x;
        dst.y = y;
        dst.w = w;
        dst.h = h;
        SDL_RenderCopy(ren, tex, NULL, &dst);
    }
     
     
     
     
    static SDL_Rect clips[4] =
    {
         {0,0,100,100},
         {100,0,100,100},
         {0,100,100,100},
         {100,100,100,100},
    };
    void render_clip(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h,SDL_Rect *src)
    {
        //Setup the destination rectangle to be at the position we want
        SDL_Rect dst;
        if(!src)
            return;
        dst.x = x;
        dst.y = y;
        dst.w = w;
        dst.h = h;
        SDL_RenderCopy(ren, tex, src, &dst);
     
     
    }
     
     
    int main(int, char**){
        if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
            logSDLError(std::cout, "SDL_Init");
            return 1;
        }
     
     
        SDL_Window *window = SDL_CreateWindow("Lesson 2", 100, 100, SCREEN_WIDTH,
            SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == nullptr){
            logSDLError(std::cout, "CreateWindow");
            SDL_Quit();
            return 1;
        }
        SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
        if (renderer == nullptr){
            logSDLError(std::cout, "CreateRenderer");
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
     
     
        SDL_Texture* background = loadTexture("d:/background.png",renderer);
        SDL_Texture* image = loadTexture("d:/image (1).png",renderer);
     
     
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        int i = 0,j ,k,n = 0;
     
     
        SDL_Event e;
        bool quit = false;
        while (!quit){
            while (SDL_PollEvent(&e)){
                if (e.type == SDL_QUIT){
                    quit = true;
                }
                if (e.type == SDL_KEYDOWN){
                    //switch (event.key.keysym.sym)
                    switch(e.key.keysym.sym)
                    {
                       case SDLK_ESCAPE:
                            quit = true;
                            break;
                       case SDLK_SPACE:
                       case SDLK_r:
                            i++;
                            n++;
                            break;
                       default:
                            break;
                    }
     
     
                }
                if (e.type == SDL_MOUSEBUTTONDOWN){
                    //quit = true;
                }
            }
            SDL_RenderClear(renderer);
            for(j = 0; j < (SCREEN_HEIGHT /30)+1; j++)
            {
                for(k = 0; k< (SCREEN_WIDTH /30)+1; k++)
                {
                    renderTexture(background,renderer,k*30,j*30,30,30);
                }
            }
     
     
            render_clip(image,renderer,i*30,i*30,100,100,&(clips[n%4]));
            SDL_RenderPresent(renderer);
        }
     
     
        SDL_DestroyTexture(background);
        SDL_DestroyTexture(image);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        std::cout<<"ok"<<std::endl;
        return 0;
    }
    #endif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    #ifdef LESSON_4
    #include <iostream>
    #include <SDL.h>
    #include <SDL_image.h>
    using namespace std;
     
     
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
     
     
     
     
    const int SCREEN_WIDTH  = 640;
    const int SCREEN_HEIGHT = 480;
    //We'll just be using square tiles for now
    const int TILE_SIZE = 40;
     
     
    void logSDLError(std::ostream &os, const std::string &msg)
    {
        os << msg << " error: " << SDL_GetError() << std::endl;
    }
     
     
    SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
        SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
        if (texture == nullptr){
            logSDLError(std::cout, "LoadTexture");
        }
        return texture;
    }
    void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){
        //Setup the destination rectangle to be at the position we want
        SDL_Rect dst;
        dst.x = x;
        dst.y = y;
        dst.w = w;
        dst.h = h;
        SDL_RenderCopy(ren, tex, NULL, &dst);
    }
     
     
     
     
    int main(int, char**){
        if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
            logSDLError(std::cout, "SDL_Init");
            return 1;
        }
     
     
        SDL_Window *window = SDL_CreateWindow("Lesson 2", 100, 100, SCREEN_WIDTH,
            SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == nullptr){
            logSDLError(std::cout, "CreateWindow");
            SDL_Quit();
            return 1;
        }
        SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
        if (renderer == nullptr){
            logSDLError(std::cout, "CreateRenderer");
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
     
     
        SDL_Texture* background = loadTexture("d:/background.png",renderer);
        SDL_Texture* image = loadTexture("d:/image.png",renderer);
     
     
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        int i = 0,j ,k;
     
     
        SDL_Event e;
        bool quit = false;
        while (!quit){
            while (SDL_PollEvent(&e)){
                if (e.type == SDL_QUIT){
                    quit = true;
                }
                if (e.type == SDL_KEYDOWN){
                    //switch (event.key.keysym.sym)
                    switch(e.key.keysym.sym)
                    {
                       case SDLK_ESCAPE:
                            quit = true;
                            break;
                       case SDLK_SPACE:
                        case SDLK_r:
                            i++;
                            break;
                       default:
                            break;
                    }
     
     
                }
                if (e.type == SDL_MOUSEBUTTONDOWN){
                    //quit = true;
                }
            }
            SDL_RenderClear(renderer);
            for(j = 0; j < (SCREEN_HEIGHT /30)+1; j++)
            {
                for(k = 0; k< (SCREEN_WIDTH /30)+1; k++)
                {
                    renderTexture(background,renderer,k*30,j*30,30,30);
                }
            }
     
     
            renderTexture(image,renderer,i*30,i*30,100,100);
     
     
            SDL_RenderPresent(renderer);
        }
     
     
        SDL_DestroyTexture(background);
        SDL_DestroyTexture(image);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        std::cout<<"ok"<<std::endl;
        return 0;
    }
    #endif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    #ifdef LESSON_3
    #include <iostream>
    #include <SDL.h>
    #include <SDL_image.h>
    using namespace std;
     
     
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
     
     
     
     
    const int SCREEN_WIDTH  = 640;
    const int SCREEN_HEIGHT = 480;
    //We'll just be using square tiles for now
    const int TILE_SIZE = 40;
     
     
    void logSDLError(std::ostream &os, const std::string &msg)
    {
        os << msg << " error: " << SDL_GetError() << std::endl;
    }
     
     
    SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
        SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
        if (texture == nullptr){
            logSDLError(std::cout, "LoadTexture");
        }
        return texture;
    }
    void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){
        //Setup the destination rectangle to be at the position we want
        SDL_Rect dst;
        dst.x = x;
        dst.y = y;
        dst.w = w;
        dst.h = h;
        SDL_RenderCopy(ren, tex, NULL, &dst);
    }
     
     
     
     
    int main(int, char**){
        if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
            logSDLError(std::cout, "SDL_Init");
            return 1;
        }
     
     
        SDL_Window *window = SDL_CreateWindow("Lesson 2", 100, 100, SCREEN_WIDTH,
            SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == nullptr){
            logSDLError(std::cout, "CreateWindow");
            SDL_Quit();
            return 1;
        }
        SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
        if (renderer == nullptr){
            logSDLError(std::cout, "CreateRenderer");
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
     
     
        SDL_Texture* background = loadTexture("d:/background.png",renderer);
        SDL_Texture* image = loadTexture("d:/image.png",renderer);
     
     
        SDL_RenderClear(renderer);
        SDL_RenderPresent(renderer);
        int i,j ,k;
        for (i = 0; i < 30; ++i)
        {
            for(j = 0; j < (SCREEN_HEIGHT /30)+1; j++)
            {
                for(k = 0; k< (SCREEN_WIDTH /30)+1; k++)
                {
                    renderTexture(background,renderer,k*30,j*30,30,30);
                }
            }
            renderTexture(image,renderer,i*30,i*30,100,100);
            SDL_RenderPresent(renderer);
            SDL_Delay(1000);
        }
     
     
        SDL_DestroyTexture(background);
        SDL_DestroyTexture(image);
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        std::cout<<"ok"<<std::endl;
        return 0;
    }
    #endif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    #ifdef LESSON_2
    #include <iostream>
    #include <SDL.h>
    using namespace std;
     
     
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
     
     
    const int SCREEN_WIDTH  = 640;
    const int SCREEN_HEIGHT = 480;
     
     
    void logSDLError(std::ostream &os, const std::string &msg){
        os << msg << " error: " << SDL_GetError() << std::endl;
    }
     
     
    SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren)
    {
            if(!ren)
                return NULL;
            SDL_Surface *bmp = SDL_LoadBMP(file.c_str());
            if(bmp == nullptr)
            {
                logSDLError(cout, "SDL_LoadBMP");
                return NULL;
            }
            SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
            SDL_FreeSurface(bmp);
            if(tex == nullptr)
            {
                logSDLError(cout, "SDL_CreateTextureFromSurface");
                return NULL;
            }
            return tex;
    }
     
     
    void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y){
        //Setup the destination rectangle to be at the position we want
        SDL_Rect dst;
        dst.x = x;
        dst.y = y;
        //Query the texture to get its width and height to use
        SDL_QueryTexture(tex, NULL, NULL, &dst.w, &dst.h);
        SDL_RenderCopy(ren, tex, NULL, &dst);
    }
     
     
     
     
     
     
    int main(int, char**){
        if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
            logSDLError(std::cout, "SDL_Init");
            return 1;
        }
     
     
        SDL_Window *window = SDL_CreateWindow("Lesson 2", 100, 100, SCREEN_WIDTH,
            SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == nullptr){
            logSDLError(std::cout, "CreateWindow");
            SDL_Quit();
            return 1;
        }
        SDL_Renderer *renderer = SDL_CreateRenderer(window, -1,
            SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
        if (renderer == nullptr){
            logSDLError(std::cout, "CreateRenderer");
            SDL_DestroyWindow(window);
            SDL_Quit();
            return 1;
        }
        SDL_Texture *background = loadTexture("d:/background.bmp",renderer);
        SDL_Texture *image      = loadTexture("d:/image.bmp",renderer);
     
     
        SDL_RenderClear(renderer);
        renderTexture(background,renderer,20,20);
        for (int i = 0; i < 30; ++i)
        {
            //SDL_RenderClear(renderer);
            //renderTexture(background,renderer,20,20);
            renderTexture(image,renderer,20+30*i,20+30*i);
            SDL_RenderPresent(renderer);
            SDL_Delay(1000);
        }
     
     
        SDL_DestroyTexture(background);
        SDL_DestroyTexture(image);
     
     
        SDL_DestroyRenderer(renderer);
        SDL_DestroyWindow(window);
        SDL_Quit();
        std::cout<<"ok"<<std::endl;
        return 0;
    }
    #endif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    #ifdef LESSON_1
    #include <iostream>
    #include <SDL.h>
    using namespace std;
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
     
     
    int main(int, char**)
    {
        if(SDL_Init(SDL_INIT_VIDEO) != 0)
        {
            cout<<"SDL_Init Error:"<<SDL_GetError()<<endl;
            return 1;
        }
        SDL_Window *win = SDL_CreateWindow("Hello world!",100,100,640,480,SDL_WINDOW_SHOWN);
        if(win == nullptr)
        {
            cout<<"SDL_CreateWindow Error:"<<SDL_GetError()<<endl;
            SDL_Quit();
            return 1;
        }
        SDL_Renderer *ren = SDL_CreateRenderer(win,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
        if(ren == nullptr)
        {
            SDL_DestroyWindow(win);
            std::cout << "SDL_CreateRenderer Error: " << SDL_GetError() << std::endl;
            SDL_Quit();
            return 1;
        }
        string imagepath = string("d:/")+"hello.bmp";
        SDL_Surface *bmp = SDL_LoadBMP(imagepath.c_str());
        if (bmp == nullptr){
            SDL_DestroyRenderer(ren);
            SDL_DestroyWindow(win);
            std::cout << "SDL_LoadBMP Error: " << SDL_GetError() << std::endl;
            SDL_Quit();
            return 1;
        }
        SDL_Texture *tex = SDL_CreateTextureFromSurface(ren, bmp);
        SDL_FreeSurface(bmp);
        if (tex == nullptr){
            SDL_DestroyRenderer(ren);
            SDL_DestroyWindow(win);
            std::cout << "SDL_CreateTextureFromSurface Error: " << SDL_GetError() << std::endl;
            SDL_Quit();
            return 1;
        }
     
     
        for (int i = 0; i < 3; ++i){
            //First clear the renderer
            cout<<"before call SDL_RenderClear(ren)"<<endl;
            SDL_Delay(2000);
            SDL_RenderClear(ren); //这里的ren指的是"后台缓存",把它清掉,不影响前台显示。
            SDL_RenderPresent(ren);//这里会把后台缓存更新到前台,所以显示黑色窗口了。
            cout<<"after call SDL_RenderClear(ren)"<<endl;
            SDL_Delay(2000);
            cout<<"before call SDL_RenderCopy"<<endl;
            SDL_Delay(2000);
            //Draw the texture
            SDL_RenderCopy(ren, tex, NULL, NULL); // 这里是把SDL_Texture 的整个部分copy到ren
            cout<<"after call SDL_RenderCopy"<<endl;
            SDL_Delay(2000);
            //Update the screen
            cout<<"before call SDL_RenderPresent"<<endl;
            SDL_Delay(2000);
            SDL_RenderPresent(ren);
            cout<<"after call SDL_RenderPresent"<<endl;
            SDL_Delay(2000);
            //Take a quick break after all that hard work
            SDL_Delay(1000);
        }
        Sleep(1000);
        SDL_DestroyTexture(tex);
        SDL_DestroyRenderer(ren);
        SDL_DestroyWindow(win);
        SDL_Quit();
     
     
     
     
    }
     
     
    #endif
     
     
     
     
     
     
     
     
     
     
     
     
     
     
    #ifdef LESSON_0
    #include <iostream>
    #include <SDL.h>
     
     
    /*
     * Lesson 0: Test to make sure SDL is setup properly
     */
    #undef main
    int main(int, char**){
        if (SDL_Init(SDL_INIT_VIDEO) != 0){
            std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl;
            return 1;
        }
        SDL_Quit();
        std::cout<<"ok"<<std::endl;
        return 0;
    }
    #endif
    
    

    转载于:https://www.cnblogs.com/wxmcu/p/8728441.html

    展开全文
  • SDL简介

    2015-11-04 10:43:37
    SDL即Simple DirectMedia Layer,类似DirectX,是完整的游戏、多媒体开发包,但不同的是它跨越几乎所有的平台,有各种语言的接口,多种语言的文档,而这一切都是广大志愿者完成的。目前扩展部分还没有正式的文档,...
  • 本节课学习使用SDL2封装一个透明背景的window,并在window上使用SDL_Renderer和SDL_Texture进行绘图 圆形没有反走样 计算机几何算法B站有个孔令德老师讲课挺好的,建议看看 (我只看了两节课,后面工作不忙了再认真...
  • SDL安装

    2013-09-08 19:32:58
    C语言没有图形库,似乎编写C语言的程序就要面对那个黑黑的控制台窗口,这也是很多人对C语言提不起兴趣的原因,但我们可以使用第三方的图形库,比如说open GL,directX,SDL等等,其中SDL比较小巧,并且是开源的,...
  • SDL视频渲染教程

    2019-12-27 13:26:58
    #include <SDL2/SDL.h> int main() { SDL_Window *window=NULL; SDL_Renderer *render=NULL; SDL_Texture *texture=NULL; SDL_Event event; SDL_Rect rect; int quit=0; //初始化环境...
  • SDL入门操练

    2019-12-07 22:33:52
    本文使用SDL作为图形库,实现了在一个界面上, 隔一会就出来一个方块,算是学习SDL图形库的入门, 为了方便, 使用了Qt IDE, 而不是在Linux上构建。对于新手来说,对各个函数的名称, 参数, 作用, 返回值都不熟悉...
  • SDL工程中让SDL_ttf渲染汉字

    千次阅读 2014-12-29 17:48:32
    有时候在关于SDL的博文中看到一些评论,说SDL对中文的支持不佳,因为当程序涉及中文时总是输出乱码。 照我个人观点,这里面很多都是误解。下面就根据我在windows下使用SDL的情况,说说我的观点。 SDL作为一个跨...
  • SDL显示文字

    千次阅读 2014-12-29 17:46:12
    前面教程里,我们只显示图片,没提到如何显示文字, SDL本身没有显示文字功能,它需要用扩展库SDL_ttf来显示文字。ttf是True Type Font的缩写,ttf是Windows下的缺省字体,它有美观,放大缩小不变形的优点,因此...
  • Android 编译SDL2

    2020-09-25 14:49:08
    Android 使用cmake 编译SDL2 SDL2官网下载 如这里解压得到 SDL2-2.0.12: 几个重要的目录与文件说明 android-project: Android 项目的模板项目 docs:说明文档 include:SDL2的头文件 src:SDL2的源文件 Android....
  • SDL检测按键

    2019-12-08 16:06:23
    文章目录preface按键检测基础EVENT基础event类型event结构体代码示例:示例...那么如果用SDL实现的播放器是怎么检测哪个键按下去了呢?大家可以直接看代码示例, 前面都是铺垫 按键检测基础 EVENT基础 event类型...
  • SDL调试心得(MFC SDL 窗口放大后 画面卡死)
  • SDL音视频渲染

    2021-03-21 11:51:22
    SDL音视频渲染 目录 SDL简介 SDL窗口显示 SDL Event事件 SDL Thread SDL PCM播放 SDL YUV播放 1. SDL基本介绍 1. SDL简介 SDL(Simple DirectMedia Layer)是一套开放源代码的跨平台多媒体开发库,使用C语言写...
  • SDL(Simple DirectMedia Layer)是一个自由的跨平台的多媒体开发包,适用于游戏、游戏SDK、演示软件、模拟器、MPEG播放器和其他应用软件。 用途广泛 SDL音频的扩展是通过SDL_mixer来扩展的,从文档可以...
  • SDL2_Tutorials

    2015-10-13 20:04:08
    30_scrolling 31_scrolling_backgrounds 32_text_input_and_clipboard_handling 33_file_reading_and_writing 35_window_events 36_multiple_windows 37_multiple_displays 38_particle_engines 39_tiling 40_...
  • SDL游戏开发之六-简单的SDL程序

    千次阅读 2019-10-05 06:47:19
    1.最简单的SDL程序 一般的游戏在运行过程中的大部分操作都是在一个大循环里,在这个循环里进行着事件监听、绘制以及逻辑处理等。而像网络通信或者是文件读取等这些比较耗时或者堵塞的操作一般会放到子线程里面。...
  • https://blog.csdn.net/whereisdog/article/details/82769222海思osd+freetype+SDL+SDL_ttf字体 本文链接:...目录 文章目录 目录 ...SDL+FreeType+SDL_tt...
  • sdl2 bitmap测试例程

    2018-09-30 11:09:08
    2018年09月30日 11:04:11 Dwyane05 阅读数:2 编辑 位图和Blitting 你以前可能听说过位图; 可能是过时的“.bmp”图像。好吧,位图在技术上只是一种图像存储的格式,其中像素数据由一块内存表示,或者你可以说是一个...
  • SDL_WindowEventID

    千次阅读 2013-11-24 00:03:47
    SDL_WINDOWEVENT_NONE never used SDL_WINDOWEVENT_SHOWN 窗口被显示 SDL_WINDOWEVENT_HIDDEN 窗口被隐藏 SDL_WINDOWEVENT_EXPOSED 窗口被显露出来且必须被重画(梦维:...
  • 转 笔记 sdl

    2015-09-14 15:06:45
    ffmpeg+SDL能同时播放多路视频么? 如题,有能实现的大侠么? jinux发表于 2013-9-27 16:20:35 解决了,几处重点: 1 用SDL2,因为ffplay.c用的是SDL1.2.5,不支持多窗口显示。  ffplay.c的需要修改queue_picture...
  • SDL基本函数1

    千次阅读 2016-11-16 22:04:47
    1、SDL_BlitSurface() 2、SDL_CreateRenderer() 3、SDL_CreateTexture() 4、 SDL_CreateTextureFromSurface() 5、SDL_CreateWindow() 6、 SDL_Delay() 7、SDL_DestroyRenderer() 8、 SDL_...
  • SDL学习教程

    千次阅读 2013-11-24 00:17:43
    理解SDL_Surface中pixels数据块格式。SDL_PixelFormat结构的分配和释放过程。知道点对点块移、RLE块移优点和缺陷。哈希表、surface表、LRU链表协同管理图面。 SDL(Simple DirectMedia)是一个自由的跨平台...
  • SDL2踩坑记录

    2019-08-11 10:25:19
    SDL2踩坑记录 SDL_SetRenderDrawColor 作用域 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); // 最开始若没有这句,Clear的颜色会使用后面设置的blue SDL_RenderClear(renderer); SDL_SetRenderDrawColor...
  • SDL入门教程

    2020-10-20 19:36:33
    此系列教程紧紧围绕SDL(Simple DirectMedia Layer),一个跨平台的2D图形库。这个库可以帮助我们在屏幕上画各种各样的生动游戏元素。此库的下载地址 http://www.libsdl.org; 并下载“Development Libraries”和“Win32...
  • SDL 渲染纹理

    2016-04-28 17:06:00
    1 #include <windows.h> // include important windows stuff ... 3 #include "SDL.h" 4 5 #include <cstdio> 6 7 #pragma comment(lib,"SDL2.lib") 8 #pragma comment(lib...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 5,193
精华内容 2,077
热门标签
关键字:

sdl30