程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> SDL編程,sdl

SDL編程,sdl

編輯:關於C語言

SDL編程,sdl


一、簡介

SDL是一個用C編寫的跨平台的多媒體庫,它通過OpenGL和Direct3D,提供了針對音頻、視頻、鍵盤、鼠標、控制桿及3D硬件的低級別的訪問接口。它在MPEG播放軟件、模擬器以及許多游戲中得到廣泛的應用,其中包含了獲得大獎的“文明:權力的呼喚”的Linux 版本。

 

參考:

http://www.libsdl.org/

 

二、編譯安裝

參考:

http://toutiao.com/a4450957327/

 

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

運行

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved