SDL programming, sdl

Source: Internet
Author: User

SDL programming, sdl

I. Introduction

SDL is a cross-platform multi-media library written in C. It provides low-level access interfaces for audio, video, keyboard, mouse, control bar, and 3D hardware through OpenGL and Direct3D. It is widely used in MPEG playback software, simulators, and many games, including the Linux version that won the grand prize "Civilization: Power call.

 

Refer:

http://www.libsdl.org/

Ii. Compilation and Installation

Refer:

http://toutiao.com/a4450957327/

 

wget http://www.libsdl.org/release/SDL2-2.0.3.tar.gz
tar -zxvf SDL2-2.0.3.tar.gzcd SDL2-2.0.3mkdir buildcd build../configuremakemake install

 

Iii. Use instances

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;}

Compile

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

Run

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.