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.