zoukankan      html  css  js  c++  java
  • SDL编程

    一、简介

    SDL是一个用C编写的跨平台的多媒体库,它通过OpenGL和Direct3D,提供了针对音频、视频、键盘、鼠标、控制杆及3D硬件的低级别的访问接口。它在MPEG播放软件、模拟器以及许多游戏中得到广泛的应用,其中包含了获得大奖的“文明:权力的呼唤”的Linux 版本。

    参考:

     

    二、编译安装

    参考:

    wget http://www.libsdl.org/release/SDL2-2.0.3.tar.gz
    tar -zxvf SDL2-2.0.3.tar.gz
    cd SDL2-2.0.3
    mkdir build
    cd build
    ../configure
    make
    make install

    三、使用实例

    example1.c

    //Toggle line numbers 
    #include "SDL.h"
    
    int main(int argc, char* argv[])
    {
            SDL_Window* window;
            SDL_Renderer* renderer;
    
            // Initialize SDL.
            if (SDL_Init(SDL_INIT_VIDEO) < 0)
                    return 1;
    
            // Create the window where we will draw.
            window = SDL_CreateWindow("SDL_RenderClear",
                            SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
                            512, 512,
                            0);
    
            // We must call SDL_CreateRenderer in order for draw calls to affect this window.
            renderer = SDL_CreateRenderer(window, -1, 0);
    
            // Select the color for drawing. It is set to red here.
            SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
    
            // Clear the entire screen to our selected color.
            SDL_RenderClear(renderer);
    
            // Up until now everything was drawn behind the scenes.
            // This will show the new, red contents of the window.
            SDL_RenderPresent(renderer);
    
            // Give us time to see the window.
            SDL_Delay(5000);
    
            // Always be sure to clean up
            SDL_Quit();
            return 0;
    }

    编译

    gcc example1.c -o example1 -I/root/workspace/exercise/languages/c/graph/sdl/SDL2-2.0.3/include -L/root/workspace/exercise/languages/c/graph/sdl/SDL2-2.0.3/build/build/.libs -lSDL2

    运行

    image

  • 相关阅读:
    Study Plan The FortyEighth Day
    原码与补码
    【innoDB】加锁案例分析
    【InnoDB】事务基础知识
    了解 CAP
    妙用位运算
    Go学习笔记
    .NET Hot Reload热重载
    .NET 6 中的 dotnet monitor
    C# 实现多线程的同步方法详解
  • 原文地址:https://www.cnblogs.com/274914765qq/p/4638292.html
Copyright © 2011-2022 走看看