Ubuntu14.04 C ++ to develop SDL2 applications, ubuntu14.04sdl2

Source: Internet
Author: User

Ubuntu14.04 C ++ to develop SDL2 applications, ubuntu14.04sdl2

1. Download and install

Go to http://www.libsdl.org/download http://www.libsdl.org/release/sdl2-2.0.3.zipsource code

Decompress the package

./Configure

Make

Sudo make install

Check

Header file:/usr/local/include/SDL2

Library location:/usr/local/lib


2. Create a test program:

# Include <iostream> # include <SDL. h> # define WIDTH 640 # define HEIGHT 480 # define BPP 4 # define DEPTH 32 using namespace std; int main (int argc, char * argv []) {SDL_Surface * screen; SDL_Event event; int keypress = 0; int h = 0; if (SDL_Init (SDL_INIT_EVERYTHING) =-1) {cout <"error:" <SDL_GetError () <endl; return 1;} SDL_Window * window = SDL_CreateWindow ("hello", SDL_WINDOWPOS_CENTERED, SDL_WINDO WPOS_CENTERED, 640,480, SDL_WINDOW_SHOWN); if (window = NULL) {cout <"Error:" <SDL_GetError () <endl; return 1 ;} SDL_Renderer * renderer = SDL_CreateRenderer (window,-1, callback | SDL_RENDERER_PRESENTVSYNC); if (renderer = NULL) {cout <"Error:" <SDL_GetError () <endl; return 1;} SDL_Surface * surface = SDL_LoadBMP ("bk.bmp"); SDL_Texture * texture = SDL_CreateTextureFrom Surface (renderer, surface); SDL_FreeSurface (surface); SDL_RenderClear (renderer); // clear the screen SDL_RenderCopy (renderer, texture, 0, 0 ); // draw texture to renderer SDL_RenderPresent (renderer); while (! Keypress) {// DrawScreen (screen, h ++); while (SDL_PollEvent (& event) {switch (event. type) {case SDL_QUIT: keypress = 1; break; case SDL_KEYDOWN: keypress = 1; break ;}} SDL_Quit (); return 0 ;}

3. Compile the build file with the following content:

G ++ sdl_app1.cpp-I/usr/local/include/SDL2-L/usr/local/lib-lSDL2-lpthread

Set the execution permission for the file:

Chmod + x build

Run the compilation command:

./Build

Generate the execution File a. out


4. Run the program

./A. out

If no. so.0.0. dynamic link library is found

Run the following command:

Sudo vim/etc/ld. so. conf # modify the system shared library search path

Add

Include/usr/local/lib

Run the following command:

Sudo ldconfig

Run./a. out

The result is running normally.





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.